Reputation: 11
I maintain/develop a angular web-app that uses a lot of ngrx selectors with props.
After upgrading it from Angular v9 to v13, I have had to refactor these selectors, because RFC: Deprecate Selectors With Props deprecated NGRX's selectors with props, in favour of factory selectors. This refactoring was pretty straight-forward, but it has had an impact on the testing.
In particular, I cannot make work jasmine tests that previously worked checking how the selectors with props were called. Before, testing what arguments were passed to the store.select function was possible like this:
spyOn(store, 'select');
expect(store.select).toHaveBeenCalledWith( selectorWithPropsFnName, Props );
But now, when the above syntax is update to cope with the new ngrx selectors approach to this:
spyOn(store, 'select');
expect(store.select).toHaveBeenCalledWith( selectorWithPropsFnName(Props) );
the test fails with the error message:
Expected [ Function ] to equal [ Function ].
Can anyone shed some light on how one is supposed to test this now?
Thanks!
Upvotes: 1
Views: 1592
Reputation: 181
We can use like following will help you out.
#declare store at primary describe level
let store: MockStore;
#add provider at TestBed Configuaration
provideMockStore({initialState: {}}),
#get injected mock store
store = TestBed.inject(MockStore);
#mock selectors
#store.ovverideSelector(selectorName,value);
#example
store.ovverrideSelector(selectUserId, '1');
Upvotes: 0