Testing: Automate memoized selector setup clear#4938
Conversation
| useOnce: true, | ||
| } ); | ||
|
|
||
| cachedSelectors = filter( selectors, property( 'clear' ) ); |
There was a problem hiding this comment.
Technically you could put it out of beforeAll and make it const.
There was a problem hiding this comment.
Yeah, if I'm being honest, I'm not sure what difference is had between putting something in beforeAll vs. the top-level describe scope, so I was inclined to keep this as part of the lifecycle of the tests actually being run (assuming that's a valid distinction).
There was a problem hiding this comment.
Agreed, it's not clear. When describe block is processed it executes all code in the scope and schedules all those special functions for future. So this is undocumented beforeBeforeAll step :) I put more things in the top-level describe these days. One use case when you would always use beforeAll is when you need to finish an async task.
gziolo
left a comment
There was a problem hiding this comment.
Good idea to trigger cache reset for every selector after each test. I also like how you filter selectors which are memoized 👍
This pull request seeks to improve selector tests to automate memoized selector cache clearing. Gutenberg includes memoized selectors via rememo whose cache can taint the result of subsequent tests if not cleared during test lifecycle. Previously, this relied on the developer implementing caching to a selector to include their selector's
clearcall in the selector tests'beforeEachmethod. With these changes, this has been automated to remove manual developer intervention, detecting which selectors are cached, and automatically clearing them.Testing instructions:
Verify that unit tests pass: