spectator icon indicating copy to clipboard operation
spectator copied to clipboard

Return-Type of SpectatorService#inject

Open LukasMachetanz opened this issue 2 years ago • 0 comments

Is this a regression?

No

Description

Let's assume that we create SomeService like defining a provider with the NGRX utility provideMockStore.

const createService = createServiceFactory({
   service: SomeService,
   providers: [provideMockStore()]
});

And let's assume having the following helper function in place:

function getMockStore(spectator: SpectatorService<SynonymListsService>): SpyObject<MockStore> {
   return spectator.inject(MockStore);
}

Finally assume that we use it something like this:

const spectator = createService();
...
expect(getMockStore(spectator).dispatch).toHaveBeenCalled();

This leads to the following error: Expected a spy, but got Function.

Apparently the result of spectator.inject(MockStore) is not SpyObject<MockStore>. Seeing the type declarations I would assume something different though. Is this expected or do I understand something wrong?

The issue can be resolved manually spying on the method dispatch like: spyOn(getMockStore(spectator), "dispatch");. It would be convenient if this would not be necessary though.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

Error: <toHaveBeenCalledOnceWith> : Expected a spy, but got Function.
Usage: expect(<spyObj>).toHaveBeenCalledOnceWith(...arguments)
Error: <toHaveBeenCalledOnceWith> : Expected a spy, but got Function.
Usage: expect(<spyObj>).toHaveBeenCalledOnceWith(...arguments)
at <Jasmine>

Please provide the environment you discovered this bug in

Angular (Jasmine & Karama) ---> 13.0.2
Spectator --> ^9.0.0

Anything else?

No response

Do you want to create a pull request?

No

LukasMachetanz avatar Mar 30 '22 11:03 LukasMachetanz