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.

Revisions

  1. oroce revised this gist Sep 4, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions action.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    function simple(num) {
    export function simple(num) {
    return {
    type: 'add',
    payload: {
    @@ -7,7 +7,7 @@ function simple(num) {
    };
    }

    function withDispatch(num) {
    export function withDispatch(num) {
    return dispatch => {
    dispatch({
    type: 'add',
  2. oroce created this gist Sep 4, 2018.
    19 changes: 19 additions & 0 deletions action.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    function simple(num) {
    return {
    type: 'add',
    payload: {
    num
    }
    };
    }

    function withDispatch(num) {
    return dispatch => {
    dispatch({
    type: 'add',
    payload: {
    num,
    }
    });
    };
    };
    27 changes: 27 additions & 0 deletions action.spec.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    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
    }
    });
    });
    });
    3 changes: 3 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    {
    "scripts": "mocha -r should '*.spec.js'"
    }