My classes I want to mock are:
class Class<T>{ ... }
@Injectable()
Manager() { ... }
I have this :
class FakeClass<T> {
constructor(public optionsForConstructor) {
.. do sth mock some methods etc.
}
class FakeManager {
public something;
constructor() {
public something: any = new FakeManager({
..some options not important here ..
});
}
I want to test in karma using fake classes:
fdescribe('A test', () => {
let INTERVAL: number = 5000;
beforeEach(() => {
addProviders([
SUT,
{provide: MyClass, useClass: FakeClass<T>},
{provide: Manager, useClass: FakeMapIncidentController},
]);
});
fit('Should test something',
inject([MyClass, Manager], (myClass, manager) => {
let SUT = new SUT(manager); // my SUT constructor needs Manager instance
expect(true).toBe(true);
}));
But unfortunately this do not work. I get:
Cannot resolve all parameters for 'MyClass'(?).
Make sure that all the parameters are decorated with
Inject or have valid type annotations
and that 'MyClass' is decorated with Injectable. in...
What is wrong with it? It seems it should work. When I delete the provide line for MyClass (since it is not an angular Injectable() service), I get provider error. How to resolve this?
Aucun commentaire:
Enregistrer un commentaire