Skip to content
This repository was archived by the owner on Apr 11, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions app/src/containers/FeatureFirstContainer/tests/actions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import expect from 'expect';
import * as actions from '../actions';
import {
LOAD_DATA_INITIATION,
LOAD_DATA_SUCCESS,
LOAD_DATA_FAILURE,
CLEAR_DATA_ERROR,
} from '../constants';

// Testing actions is as easy as validating that the actions are dispatch
// The way you think they are being dispatched.
// Just test that your expected Action object is what is actually dispatched.
// If you need help,
// See here: http://redux.js.org/docs/recipes/WritingTests.html
describe('FeatureFirstContainer actions', () => {
it('should dispatch an action to initiate the loading process', () => {
const expectedAction = {
type: LOAD_DATA_INITIATION,
};
expect(
actions.loadDataInitiation()
).toEqual(expectedAction);
});
it('should dispatch an action to successfully finish loading', () => {
const data = {
items: [],
};
const expectedAction = {
type: LOAD_DATA_SUCCESS,
data,
};
expect(
actions.loadDataSuccess(data)
).toEqual(expectedAction);
});
it('should dispatch an action with an error describing a failure to load data', () => {
const error = {
message: 'An error occured',
};
const expectedAction = {
type: LOAD_DATA_FAILURE,
error,
};
expect(
actions.loadDataFailure(error)
).toEqual(expectedAction);
});
it('should dispatch an action to clear the error', () => {
const expectedAction = {
type: CLEAR_DATA_ERROR,
};
expect(
actions.clearDataError()
).toEqual(expectedAction);
});
});
91 changes: 91 additions & 0 deletions app/src/containers/FeatureFirstContainer/tests/reducer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import * as types from '../constants';
import reducer from '../reducer';
import expect from 'expect';

const initialState = {
isLoading: false,
data: {},
error: {},
};

// testing reducers is really simple.
// pass the reducer initial state, an action and assert the output.
// Easy as cake, but if you need help
// See here: http://redux.js.org/docs/recipes/WritingTests.html
describe('featureComponent reducer', () => {
it('should return the initialState', () => {
expect(
reducer(undefined, {})
).toEqual(initialState);
});
it('should initiate loading', () => {
const stateAfter = {
isLoading: true,
data: {},
error: {},
};
expect(
reducer(initialState, {
type: types.LOAD_DATA_INITIATION,
})
).toEqual(stateAfter);
});
it('should load data successfully', () => {
const data = {
items: ['🤓', '😎', '🤔'],
};
const stateAfter = {
isLoading: false,
data,
error: {},
};
expect(
reducer(
initialState,
{
type: types.LOAD_DATA_SUCCESS,
data,
}
)
).toEqual(stateAfter);
});
it('should fail gracefully when the data doesn\'t load', () => {
const error = {
message: 'An error occured',
};
const stateAfter = {
isLoading: false,
data: {},
error,
};
expect(
reducer(
initialState,
{
type: types.LOAD_DATA_FAILURE,
error,
}
)
).toEqual(stateAfter);
});
it('should clear the errors', () => {
const stateBefore = {
isLoading: false,
error: { message: 'An error has occured' },
data: {},
};
const stateAfter = {
isLoading: false,
error: {},
data: {},
};
expect(
reducer(
stateBefore,
{
type: types.CLEAR_DATA_ERROR,
}
)
).toEqual(stateAfter);
});
});