Skip to content

Instantly share code, notes, and snippets.

@kolodny
Last active May 17, 2018 18:42
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kolodny/50e7384188bb5dc41ebb to your computer and use it in GitHub Desktop.
Save kolodny/50e7384188bb5dc41ebb to your computer and use it in GitHub Desktop.
testing redux thunk middleware
export const doTheThing = () => (dispatch, getState) => {
const users = getState();
dispatch({
type: 'THE_THING',
users,
});
};
import expect from 'expect';
describe('doTheThing', () => {
it('should return a function', () => {
expect(doTheThing()).toBeA('function');
})
it('dispatch a doTheThing action', () => {
const getState = () => ({users: 'foo'});
const dispatch = expect.createSpy();
doTheThing()(dispatch, getState);
expect(dispatch).toHaveBeenCalledWith({type: 'THE_THING', users: 'foo'});
})
});
@andywer
Copy link

andywer commented Mar 21, 2016

PS: This might also be useful! reduxjs/redux#546

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment