Replies: 1 comment 1 reply
-
Heh, I hate to rain on your parade twice in one day, but yeah, that's not really feasible here :) For one thing it would require having some kind of magic global hook into every single selector that ever gets created. That seems complicated, and a lot of effort. Memoized selectors are most definitely stateful. That's their whole purpose. If you're testing just a selector by itself, then your best bet is to create a new instance of the selector in the test: let selectSomeThing
beforeEach(() => {
selectSomeThing = goMakeMeANewSelectorInstance()
}) Alternately, if you're using Jest, it clears out the module import cache for every separate test file. So, splitting up tests into separate files may be an option here. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Context
I have a unit test that is checking
selectFoo.recomputations()
to confirm that recomputation only happens when it should. My test started failing due to a seemingly-unrelated change, and it turns out it was because I never calledselectFoo.resetRecomputations()
before my test.I finally realized that memoized selectors are inherently stateful, and that my original test was almost certainly invalid and only passing because (weird reasons that I don't care enough to understand).
The Problem (if you can call it that)
I'd like each of my tests to start with a completely clean slate to prevent this issue from happening again. I don't see a good way to do this right now. It's not really practical to manually reset the cache & recomputations on every single one of my memoized selectors.
Idea
Add a top-level export to reselect like
completelyResetAllOfMySelectors()
which can be called in abeforeEach
block. This could work by having reselect "remember" all of the selectors it has created so it can reset each one. Though I can also think of a different way to accomplish it.Would this feature actually be useful to the community? I leaning towards "no" but I already wrote up the post so 🤷♀️
Beta Was this translation helpful? Give feedback.
All reactions