Skip to content

Instantly share code, notes, and snippets.

@oroce

oroce/action.js

Last active Sep 4, 2018
Embed
What would you like to do?
testing an action
export function simple(num) {
return {
type: 'add',
payload: {
num
}
};
}
export function withDispatch(num) {
return dispatch => {
dispatch({
type: 'add',
payload: {
num,
}
});
};
};
import * as actions from './actions';
import sinon from 'sinon';
describe('simple', () => {
it('should return add action with the num passed', () => {
action.simple(4).should.eql({
type: 'add',
payload: {
num: 4
}
});
});
});
describe('withDispatch', () => {
it('should dispatch add action with the num passed', () => {
const dispatch = sinon.stub();
action.withDispatch(3)(dispatch);
dispatch.calledOnce.should.be.true();
dispatch.getCall(0).args[0].should.eql({
type: 'add',
payload: {
num: 3
}
});
});
});
{
"scripts": "mocha -r should '*.spec.js'"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment