Skip to content

Commit 9cd9056

Browse files
Add a test to verify that redux enhancer is still calling setContext with updated store avec reducer being replaced
1 parent b583710 commit 9cd9056

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

packages/react/test/redux.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,4 +425,37 @@ describe('createReduxEnhancer', () => {
425425
expect(mockHint.attachments).toHaveLength(0);
426426
});
427427
});
428+
429+
it('restore itself when calling store replaceReducer', () => {
430+
const enhancer = createReduxEnhancer();
431+
432+
const initialState = {};
433+
434+
const ACTION_TYPE = 'UPDATE_VALUE';
435+
const reducer = (state: Record<string, unknown> = initialState, action: { type: string; newValue: any }) => {
436+
if (action.type === ACTION_TYPE) {
437+
return {
438+
...state,
439+
value: action.newValue,
440+
};
441+
}
442+
return state;
443+
};
444+
445+
const store = Redux.createStore(reducer, enhancer);
446+
447+
store.replaceReducer(reducer);
448+
449+
const updateAction = { type: ACTION_TYPE, newValue: 'updated' };
450+
store.dispatch(updateAction);
451+
452+
expect(mockSetContext).toBeCalledWith('state', {
453+
state: {
454+
type: 'redux',
455+
value: {
456+
value: 'updated',
457+
},
458+
},
459+
});
460+
});
428461
});

0 commit comments

Comments
 (0)