Skip to content

Instantly share code, notes, and snippets.

@manoj-mass
Last active July 6, 2021 07:09
Show Gist options
  • Save manoj-mass/8bda8991519f129acfe061d128331766 to your computer and use it in GitHub Desktop.
Save manoj-mass/8bda8991519f129acfe061d128331766 to your computer and use it in GitHub Desktop.
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import header, { loadHeader, ACTION_TYPES } from 'app/shared/reducers/header';
describe('Header reducer tests', () => {
it('should return the initial state', () => {
const headerState = header(undefined, {});
expect(headerState).toMatchObject({
headerTitle: '',
});
});
it('should correctly detect update in current Header state', () => {
const headerState = header(undefined, { type: ACTION_TYPES.SET_HEADERDETAILS, payload: { header: 'header title' } });
expect(headerState).toMatchObject({ headerTitle: headerState.headerTitle });
const updatedHeaderState = header(
{
loading: false,
headerTitle: 'header title',
},
{ type: ACTION_TYPES.SET_HEADERDETAILS, payload: { header: 'header title updated' } }
);
expect(updatedHeaderState).toMatchObject({ headerTitle: updatedHeaderState.headerTitle });
});
describe('Header actions', () => {
it('dispatches SET_HEADERDETAILS actions', () => {
const expectedActions = [
{
type: ACTION_TYPES.SET_HEADERDETAILS,
payload: { header: 'header title' },
},
];
store.dispatch(loadHeader('header title'));
expect(store.getActions()).toEqual(expectedActions);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment