Add render test helper to follow suggested Redux testing practices#1392
Add render test helper to follow suggested Redux testing practices#1392zetter-rpf wants to merge 6 commits intomainfrom
Conversation
Extract a shared render helper for the mock Redux store and Provider wiring. This removes repetitive setup from each test case so scenarios focus on state differences instead of store plumbing, which aligns with Redux testing guidance to keep tests maintainable. Co-authored-by: Chris Zetter <zetter-rpf@users.noreply.github.com>
Replace redux-mock-store with configureStore + root reducer so tests exercise real reducer behavior, matching Redux's recommended integration testing pattern. Assertions now verify observable store state changes instead of mocked dispatched-action arrays, which reduces false confidence and avoids mock-store deprecation warnings. Co-authored-by: Chris Zetter <zetter-rpf@users.noreply.github.com>
Create a reusable Redux-aware render helper so component tests can share one Provider/store setup pattern. Updating SaveButton to use this keeps Redux test wiring consistent with the recommended real-store approach while reducing per-test boilerplate and making future migrations easier. Co-authored-by: Chris Zetter <zetter-rpf@users.noreply.github.com>
Remove the local renderSaveButton wrapper and call renderWithProviders directly in each setup block. This keeps the test aligned to the shared utility API, avoids an extra indirection layer, and makes the common pattern easier to copy into other Redux-connected tests. Co-authored-by: Chris Zetter <zetter-rpf@users.noreply.github.com>
Use preloadedState naming and object shorthand when calling renderWithProviders. This matches Redux Toolkit terminology and removes repetitive key:value syntax, making each setup block clearer and more consistent. Co-authored-by: Chris Zetter <zetter-rpf@users.noreply.github.com>
|
Cursor Agent can help with this pull request. Just |
Remove unused store bindings in scenarios that only verify rendered button classes. This resolves no-unused-vars warnings from yarn lint and keeps the setup focused on the behavior each test actually asserts. Co-authored-by: Chris Zetter <zetter-rpf@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a shared renderWithProviders test helper to reduce Redux boilerplate in component tests, and migrates SaveButton tests to use a real RTK store instead of redux-mock-store.
Changes:
- Introduce
src/utils/renderWithProviders.jsto create/configure a Redux store and wrap renders withreact-redux’s<Provider>. - Update
SaveButton.test.jsto use the new helper and assert state changes via the real reducer/store.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/utils/renderWithProviders.js | New RTL helper to render UI with a configured RTK store + Redux provider. |
| src/components/SaveButton/SaveButton.test.js | Refactors tests to use renderWithProviders and validate save behavior against real store state. |
Comments suppressed due to low confidence (1)
src/components/SaveButton/SaveButton.test.js:11
logInHandleris shared across all tests in this file and is never reset, so later assertions likeexpect(logInHandler).toHaveBeenCalled()can pass due to calls from earlier tests rather than the click under test. Clear the mock in abeforeEach/afterEach(or asserttoHaveBeenCalledTimes(1)after clearing) to make these event tests independent and reliable.
const logInHandler = jest.fn();
describe("When project is loaded", () => {
beforeAll(() => {
document.addEventListener("editor-logIn", logInHandler);
});
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| ui, | ||
| { preloadedState, store, reducer = rootReducer, ...renderOptions } = {}, | ||
| ) => { | ||
| const testStore = store || configureStore({ reducer, preloadedState }); |
There was a problem hiding this comment.
In the redux example, it set up the apps root store instead of using configure store.
I want to look at this again to see if we can follow that pattern - this would mean that tests would use the same initial store as the app which might mean less setup
In our tests we have a lot of boilerplate to set up redux state and providers in order to render components.
Redux suggests adding a
renderWithProvidershelper to manage this and make testing easier. See https://redux.js.org/usage/writing-testsThese changes add a
renderWithProvidershelper and changes a spec to use it.If we're happy with this approach we can gradually move our existing tests over as we work on them.
One thing I wasn't sure about was naming of the helper and props - I've followed the example from redux, but it might be simpler and fit in with our existing code better if we call it
renderandinitialStatethanpreloadedState(howeverrenderwill need to be renamed when imported if we want to mix styles in single test file).