Test improvements
See original GitHub issueWorking on #403 exposed a couple of potential improvements for the tests. I’m creating this issue to align which ones should actually be done, and how the changes should be grouped into PRs.
-
Reduce the usage of
any
in test files (#417)- Came up here
- Would mean to add quite some type definitions to test files. Too much boilerplate? But types are nice, so I’m in favour of doing it.
-
Remove unnecessary mocks of
console.error
(#420) -
Rename persistSync.test.tsx to.ts
as it doesn’t contain any JSX. -
Rename persist.test.tsx to
persistAsync.test.tsx
to be consistent. (#416) -
Wrap tests in persist.test.tsx into a
describe()
block to be consistent with [persistSync.test.tsx] (#416)(https://github.com/pmndrs/zustand/blob/master/tests/persistSync.test.tsx)- or should this be done with all test files?
-
persist.test.tsx: Make sure that
onRehydrateStorage
was not called with an error (#423)- I noticed that the tests will not fail on errors occurring during state initialisation as the error is only passed to
onRehydrateStorage
. Therefore each test needs to verify thatonRehydrateStorage
was called withundefined
. - I already added this check to
persistSync.test.tsx
(see example)
- I noticed that the tests will not fail on errors occurring during state initialisation as the error is only passed to
-
persist tests: Use
jest.fn()
to mockonRehydrateStorage
instead of hand-crafting a spy (#423)- See here as example
- No big deal, but my guess is that it would simplify the code, and make it more fail-safe
-
Add this test to the
persist.test.tsx
as well. (#430) -
Add some structure to basic.test.tsx (#424)
- Right now it’s 800 lines of
it()
calls 😅 - One way to add a bit of structure would be to have each
subscribe
and type-related tests be grouped under a separatedescribe()
call within the same file. - … or break up the file? Would need feedback on that one.
- Right now it’s 800 lines of
-
perstist*.test.tsx: Expand it(‘can persist state’) by verifying that the persisted state is actually written to the storage (#431)
- One of the more important scenarios, right?
-
split tests for
subscribe()
into multiple it() blocks (#427) -
replace callbacks with spies for
subscribe()
tests (#429) -
persistAsync.test.tsx
: Move componentCounter
to top of file- Tried it, doesn’t seem to be worth it. Will skip.
-
Address inconsistency of arguments for
onRehydrateStorage
between sync and async (#437)- Follow-up of this
-
Follow up on #431 (#436)
- Implement also for async version.
-
Add tests for outer
onRehydrateStorage
callback`- At the moment the tests only test the function returned by
onRehydrateStorage
which is called after rehydration, not the one that’s called before rehydration.
- At the moment the tests only test the function returned by
I guess that all of those deserve separate PRs. So I’d just need to know which ones you want to be done, then I’d get going.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Oh, right, the ticket is still open.
It can be closed as far as I’m concerned. One item is still open, but I’m doubtful that it’s important enough and worth the effort.
Closing…
I’m fine. Having new ideas after some work is not surprising. Thanks for your contributions.