I have an Angular 8 app (core 8.1.2) using NgRx and the @ngrx/router-store
(8.4.0) but am having trouble mocking a selector generated by fromRouter.getSelectors(selectRouter)
.
The selector I have written and am trying to test looks like this:
export const selectFilteredPagedFeaturedPlaylists = createSelector(
selectFilteredFeaturedPlaylists,
selectRoutePageIndex,
selectPageSize,
(featuredPlaylists, pageIndex, pageSize) => ({
...featuredPlaylists,
content: featuredPlaylists.content.slice(+pageIndex * pageSize, (+pageIndex + 1) * pageSize)
})
);
and the selectRoutePageIndex
selector, calling a method generated by the store, looks like this:
export const selectRoutePageIndex = selectRouteParam('pageIndex');
In reality, I am not necessarily concerned with mocking the selectRouteParam
selector, but I need to mock my selectRoutePageIndex
selector. Unfortunately, the technique described in the docs doesn't appear to work for selectors generated by @ngrx/router-store
.
Any ideas how I can do this?
I did not find an answer to my question, but I have created a workaround. I have wrapped the router store's selector in a
createSelector()
call and just returned it. It looks like this:So the client code still uses the
selectRoutePageIndex
selector, andMockStore.overrideSelector()
is happy with the arrangement. It seems thatcreateSelector()
is more forgiving of the signatures of the selectors it is passed.