reselect icon indicating copy to clipboard operation
reselect copied to clipboard

Reset Recomputations for Testing?

Open seriallos opened this issue 10 years ago • 2 comments

I'm writing tests for the selectors I've created and am running into a small obstacle.

There's no direct way to reset computations so if I have a complex selectors with many tests, I have to manually track what the recomputation count should be in each individual test. This is annoying to track and it would be simplest if there was something like a resetRecomputations() method I could call in a beforeEach block in my tests.

Right now my workaround is just to create a "fake" new selector in every test that uses the one I'm testing with an identity function to make sure that each individual it test has recomputations reset to 0, akin to the following:

const singleTestSelector = createSelector(actualSelector, f => f);

This seems to work fine but it's a little indirect and I feel like I'd rather have something like actualSelector.resetRecomputations() in my tests as I find it slightly clearer.

seriallos avatar Mar 03 '16 18:03 seriallos

Hey @seriallos, I just published a new version of Reselect which includes your PR to npm. Thanks again!

ellbee avatar Mar 03 '16 20:03 ellbee

Awesome! I just updated and tested in my own codebase and it's working.

Only subtle bit that should be noted is that I wasn't always correctly creating a new state object in each individual tests so I was running into 0 recomputations instead of 1 (or more) because the previous tests had already cached the result for that object. My solution was to use a function to recreate the defaults from my reducers every time instead of just defining it once and re-using.

seriallos avatar Mar 03 '16 20:03 seriallos