Last active
September 4, 2018 11:25
-
-
Save oroce/6d0d2681dd2112a5cc84c5e1d3835966 to your computer and use it in GitHub Desktop.
testing an action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function simple(num) { | |
return { | |
type: 'add', | |
payload: { | |
num | |
} | |
}; | |
} | |
export function withDispatch(num) { | |
return dispatch => { | |
dispatch({ | |
type: 'add', | |
payload: { | |
num, | |
} | |
}); | |
}; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"scripts": "mocha -r should '*.spec.js'" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment