如何为Jasmine测试创建Aurelia Validation Validation对象



我目前正在使用Aurelia验证插件进行客户端验证。由于验证对象必须注入到调用类的构造函数中,我对该类的所有茉莉花测试现在都失败了(因为没有传入验证对象)

一段时间以来,我一直在尝试创建一个模拟验证对象,甚至是一个真实的验证对象,但我似乎做不好。我得到的最接近的是:

beforeEach(() => {
    cache = new Cache();
    session = new Session();
    var valCon = new ValidationConfig();
    var obsLoc = new ObserverLocator();
    sut = new InsuredInformation(session, cache, new Validation(obsLoc,valCon));
}); 

但当我运行因果报应时,我总是会出错:

TypeError: Expecting a function in instanceof check, but got [object Object]

我认为这与验证对象以及我如何实例化它有关。有人成功地为Aurelia视图模型创建了使用Aurelia验证插件的Jasmine测试吗?

尝试使用Container实例化对象。您可能需要初始化平台抽象层。

import {Container} from 'aurelia-framework'; // or 'aurelia-dependency-injection'
import {initialize as initializePAL} from 'aurelia-pal-browser'; // you may need to `jspm install aurelia-pal-browser`
initializePAL();
beforeEach(() => {
  let container = new Container();
  sut = container.get(InsuredInformation);
  foo = container.get(SomeOtherClassThatYouWantToTest);
}); 

最新更新