Skip to content

Instantly share code, notes, and snippets.

@oroce
Last active September 4, 2018 11:25
Show Gist options
  • Save oroce/6d0d2681dd2112a5cc84c5e1d3835966 to your computer and use it in GitHub Desktop.
Save oroce/6d0d2681dd2112a5cc84c5e1d3835966 to your computer and use it in GitHub Desktop.
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