fix: make bindActionCreators thunk example runnable#310
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new test suite for the connected counter component and integrates redux-thunk middleware into the global store. The review feedback suggests several improvements to the test file, including replacing the any type in the mock reducer with a more specific action type, removing redundant cleanup() calls that are automatically handled by the testing library, and adopting more idiomatic screen.getByText assertions for better clarity and robustness.
|
|
||
| const reducer = combineReducers({ | ||
| counters: combineReducers({ | ||
| reduxCounter: (state: number = 0, action: any) => { |
There was a problem hiding this comment.
Using any for the action parameter in the reducer disables type checking. It is recommended to use a more specific type, such as RootAction from MyTypes or at least { type: string }, to maintain type safety even in test mocks.
| reduxCounter: (state: number = 0, action: any) => { | |
| reduxCounter: (state: number = 0, action: { type: string }) => { |
| afterEach(() => { | ||
| jest.useRealTimers(); | ||
| cleanup(); | ||
| }); |
| renderWithRedux(<ConnectedCounter label={label} />); | ||
|
|
||
| fireEvent.click(screen.getByText('Increment')); | ||
| expect(screen.getByText(RegExp(label)).textContent).toBe(label + ': 0'); |
There was a problem hiding this comment.
Using screen.getByText with a template literal is more direct and idiomatic than using a regex and checking textContent separately. Since getByText throws if the text is not found, the assertion is also more robust.
| expect(screen.getByText(RegExp(label)).textContent).toBe(label + ': 0'); | |
| expect(screen.getByText(`${label}: 0`)).toBeDefined(); |
| jest.advanceTimersByTime(1000); | ||
| }); | ||
|
|
||
| expect(screen.getByText(RegExp(label)).textContent).toBe(label + ': 1'); |
There was a problem hiding this comment.
|
Addressed the review suggestions in 9d36ac4. The regression spec now uses |
Summary
redux-thunkto the playground store middleware chain so the delayed counter example can dispatch thunks at runtimeFCCounterConnectedBindActionCreatorsincrement flowValidation
cd playground && export CI=true && npm test -- --runInBand --watch=false src/connected/fc-counter-connected-bind-action-creators.spec.tsxcd playground && npm run tsccd playground && npx eslint src/store/store.ts src/connected/fc-counter-connected-bind-action-creators.spec.tsxCloses #212