Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check to dispatcher for undefined action and undefined action type #40

Merged
merged 1 commit into from
Jun 5, 2016
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
13 changes: 13 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ export default function configureStore(middlewares=[]) {
},

dispatch(action) {
if (typeof action === 'undefined') {
throw new Error(
'Actions may not be an undefined.'
);
}

if (typeof action.type === 'undefined') {
throw new Error(
'Actions may not have an undefined "type" property. ' +
'Have you misspelled a constant?'
);
}

actions.push(action);

for (let i = 0; i < listeners.length; i++) {
Expand Down
18 changes: 18 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ describe('redux-mock-store', () => {
expect(store.getState()).toEqual(initialState);
});

it('should throw an error when action is undefined', () => {
const store = mockStore({});

expect(() => { store.dispatch(undefined); }).toThrow(
'Actions may not be an undefined.'
);
});

it('should throw an error when action type is undefined', () => {
const action = { types: 'ADD_ITEM' };
const store = mockStore({});

expect(() => { store.dispatch(action); }).toThrow(
'Actions may not have an undefined "type" property. ' +
'Have you misspelled a constant?'
);
});

it('should return if the tests is successful', () => {
const action = { type: 'ADD_ITEM' };
const store = mockStore({});
Expand Down