Reputation: 3393
I followed the unit testing from this website (author: Torgeir Helgevold) @:TGH http://www.syntaxsuccess.com/viewarticle/angular-2.0-unit-testing to do unit testing, but got an error:
"Error:(15, 39) TS2345: Argument of type 'FunctionWithParamTokens' is not assignable to parameter of type '(done: () => void) => void'."
it('should define full name2', inject([DisplayName], (displayName) => {
displayName.firstName = 'Joe';
displayName.lastName = 'Smith';
displayName.generateFullName();
expect(displayName.fullName).toBe('Joe Smith');
}));
Is the code in this website out of date? Can anyone give me some reference to learn unit testing with Anuglar2 + Jasmine?
Upvotes: 3
Views: 2504
Reputation: 2081
I encountered this error too. The problem was that I was not importing beforeEach
from 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');
});
});
Upvotes: 16