State Management · Senior · Question 49 of 75
Which approach makes state logic easiest to unit-test regardless of the library?
- ✓Correct answer: Keep transitions in pure functions (reducers, slice reducers, store actions) tested without rendering
- 2Test only through end-to-end tests in a real browser
- 3Mock React itself in every test
Explanation
A reducer or a store action can be tested by calling it with an input and asserting the output. Components are then tested for behavior (React Testing Library), with server calls mocked at the network layer (e.g. MSW).