Writing a unit test for a component, that uses a Service with an emit inside the constructor, like this:
@Injectable()
export class Service1 {
public onService1Done: EventEmitter<any> = new EventEmitter();
public constructor(...) {
this.onService1Done.emit(value);
}
}
I notice that, according to what i have in the component.spec.ts:
beforeEachProviders(() => {
return [
provide(Service1, { useClass: MockService1 }),
Component1
];
});
it("check that XXX", inject(
[Service1, Component1], (service1: Service1, component1: Component1) => {
service1.onService1Done.subscribe({ next: () => DoSomething() });
expect(DoSomething()).toEqual(IsDone);
}));
});
}
The constructor of Service1, and so the emit, will be called before i could make the subscribe, inside the test;
there is a way to avoid this ?? to make the subscribe before the Constructor ?
As always, thanks in advance.