我跟随本网站的单元测试(作者:Torgeir Helgevold)@:TGH http://www.syntaxsuccess.com/viewarticle/angular-2.0-unit-testing进行单元测试,但收到错误:
"错误:(15,39)TS2345:类型的参数' FunctionWithParamTokens'不能分配给'(完成:()=> void)=>类型的参数空隙'"
it('should define full name2', inject([DisplayName], (displayName) => {
displayName.firstName = 'Joe';
displayName.lastName = 'Smith';
displayName.generateFullName();
expect(displayName.fullName).toBe('Joe Smith');
}));
此网站中的代码是否已过期?谁能给我一些参考资料来学习Anuglar2 + Jasmine的单元测试?
答案 0 :(得分:16)
我也遇到了这个错误。问题是我没有从beforeEach
导入angular2/testing
。
import {it, describe, expect, inject, beforeEach} from 'angular2/testing';
describe('Thing', () => {
let thing: Thing;
beforeEach(inject([Thing], (t: Thing) => {
thing = t;
}));
it('should do something', () => {
expect(thing.doSomething()).toBe('I did a thing');
});
});