-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it possible to use MockStore's overrideSelector method against selectors given by entityAdapter.getSelectors() #3172
Comments
I'm no expert in the inner workings of ngrx, but solution 3 seems to make the most sense - in fact, I kind of expected it to be the case. |
relates #2751 |
markostanimirovic
added a commit
that referenced
this issue
Oct 18, 2023
…parent selector Closes #2751, #3172 BREAKING CHANGES: Selectors returned by the `adapter.getSelectors` signature that accepts a parent selector are strongly typed. BEFORE: ```ts const { selectIds, // type: (state: object) => string[] | number[] selectEntities, // type: (state: object) => Dictionary<Book> selectAll, // type: (state: object) => Book[] selectTotal, // type: (state: object) => number } = adapter.getSelectors(selectBooksState); ``` AFTER: ```ts const { selectIds, // type: MemoizedSelector<object, string[] | number[]> selectEntities, // type: MemoizedSelector<object, Dictionary<Book>> selectAll, // type: MemoizedSelector<object, Book[]> selectTotal, // type: MemoizedSelector<object, number> } = adapter.getSelectors(selectBooksState); ```
markostanimirovic
added a commit
that referenced
this issue
Oct 18, 2023
…parent selector Closes #2751, #3172 BREAKING CHANGES: Selectors returned by the `adapter.getSelectors` signature that accepts a parent selector are strongly typed. BEFORE: ```ts const { selectIds, // type: (state: object) => string[] | number[] selectEntities, // type: (state: object) => Dictionary<Book> selectAll, // type: (state: object) => Book[] selectTotal, // type: (state: object) => number } = adapter.getSelectors(selectBooksState); ``` AFTER: ```ts const { selectIds, // type: MemoizedSelector<object, string[] | number[]> selectEntities, // type: MemoizedSelector<object, Dictionary<Book>> selectAll, // type: MemoizedSelector<object, Book[]> selectTotal, // type: MemoizedSelector<object, number> } = adapter.getSelectors(selectBooksState); ```
markostanimirovic
added a commit
that referenced
this issue
Oct 18, 2023
…parent selector Closes #2751, #3172 BREAKING CHANGES: Selectors returned by the `adapter.getSelectors` signature that accepts a parent selector are strongly typed. BEFORE: const { selectIds, // type: (state: object) => string[] | number[] selectEntities, // type: (state: object) => Dictionary<Book> selectAll, // type: (state: object) => Book[] selectTotal, // type: (state: object) => number } = adapter.getSelectors(selectBooksState); AFTER: const { selectIds, // type: MemoizedSelector<object, string[] | number[]> selectEntities, // type: MemoizedSelector<object, Dictionary<Book>> selectAll, // type: MemoizedSelector<object, Book[]> selectTotal, // type: MemoizedSelector<object, number> } = adapter.getSelectors(selectBooksState);
3 tasks
closed by #4074 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently if a selector (
booksSelector
in this example) is created in the following way (using entityAdapter'sgetSelectors
method):then it's impossible to use the overrideSelector method in a unit test, eg.:
Because the
overrideSelector
expects aSelector
as its first parameter.I think this makes us writing unnecessary workarounds in unit tests.
3 solutions seem possible:
1: Extend the the acceptable types of the first parameter of
MockStore
'soverrideSelector
.2: Extend the MockStore with an
overrideTypelessSelector
method that is similar to the originaloverrideSelector
but it accepts these kind of selectors as first param.3: Modify the
EntityAdapter
'sgetSelectors
method to return with selectors that implementSelector
orMemoizedSelector
.Describe any alternatives/workarounds you're currently using
Currently I can't test the connection only between a state selector and a linked variable.
One of the (unwanted) workarounds is that we can change the state through the MockStore (or the entityAdapter) to trigger a change in the desired selector's value.
Another solution is to wrap the selectAll into a MemoizedSelector with createSelector.
Aaaaand the best workaround is:
:D
Other information:
Same problem is detailed on stackoverflow: https://stackoverflow.com/questions/69519000/in-unit-test-how-to-override-an-ngrx-selector-which-is-created-by-entityadapter
If accepted, I would be willing to submit a PR for this feature
(I mean I can try)
[x] Yes (Assistance is provided if you need help submitting a pull request)
[ ] No
The text was updated successfully, but these errors were encountered: