Skip to content

Instantly share code, notes, and snippets.

@tomfa
Last active August 18, 2017 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomfa/20032a5d1b636e402796c2d37ff6e624 to your computer and use it in GitHub Desktop.
Save tomfa/20032a5d1b636e402796c2d37ff6e624 to your computer and use it in GitHub Desktop.
Redux state test example
import {expect} from 'chai';
import reducer from '../../reducers/installations';
describe('reducers/installations', () => {
let state;
beforeEach(() => {
state = {
installations: [],
isLoading: False,
};
});
it('should not change state for unknown actions', () => {
let newState = reducer(state, { type: 'UNKNOWN_TYPE' });
expect(newState).to.equal(state);
});
it('should be loading on INSTALLATION_REQUESTED', () => {
let newState = reducer(state, {
type: INSTALLATION_REQUESTED,
});
expect(newState).to.deep.equal({
installations: [],
isLoading: True,
});
});
it('should populate installations on INSTALLATION_RECEIVED', () => {
let newState = reducer(state, {
type: INSTALLATION_RECEIVED,
installation: {
address: 'The Road 1',
country: 'Norway',
},
});
expect(newState).to.deep.equal({
installations: [{
address: 'The Road 1',
country: 'Norway',
}],
isLoading: True,
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment