Skip to content

Commit

Permalink
feat(gogame): Add the method playMove to GoGame prototype
Browse files Browse the repository at this point in the history
Each GoGame object now has a playMove method which calls the reducer with itself and the playMove

action and returns the result. The GoGame itself stays immutable.
  • Loading branch information
BenoitAverty committed Jun 15, 2016
1 parent 2a0b75e commit 1554ee4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"plugins": ["transform-object-rest-spread", "add-module-exports"],
"env": {
"test": {
"plugins": [["__coverage__", { "only": "src/GoGame" }]]
"plugins": [
["__coverage__", { "only": "src/GoGame" }],
"rewire",
]
}
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
"babel-loader": "^6.2.4",
"babel-plugin-__coverage__": "^1.11.111",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-rewire": "^1.0.0-rc-3",
"babel-plugin-transform-object-rest-spread": "^6.8.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.5.0",
"chai": "^3.5.0",
"chai-enzyme": "^0.4.2",
"codecov.io": "^0.1.6",
"commitizen": "^2.8.2",
"cross-env": "^1.0.8",
Expand All @@ -68,6 +68,8 @@
"nyc": "^6.4.4",
"rimraf": "^2.5.2",
"semantic-release": "^4.3.5",
"sinon": "^1.17.4",
"sinon-chai": "^2.8.0",
"webpack": "^1.13.1",
"webpack-dev-server": "^1.14.1"
},
Expand Down
3 changes: 3 additions & 0 deletions src/GoGame/GoGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ GoGame.prototype = {
get turn() {
return 'BLACK';
},
playMove({ i, j }) {
return goGameReducer(this, actions.playMove(i, j));
},
};

export default GoGame;
22 changes: 20 additions & 2 deletions test/game/GoGame.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/* eslint-env mocha */
import _ from 'lodash';
import { expect } from 'chai';
import chai, { expect } from 'chai';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
chai.use(sinonChai);

import { GoGame } from '../../src';
import { GoGame, actions } from '../../src';

describe('GoGame', () => {
describe('default / empty GoGame object', () => {
Expand Down Expand Up @@ -49,4 +52,19 @@ describe('GoGame', () => {
expect(game.turn).to.equal('BLACK');
});
});

/* eslint-disable no-underscore-dangle */
describe('playMove method', () => {
it('Should call the reducer with the playMove action and return the result', () => {
const resultGame = {};
const reducerStub = sinon.stub().returns(resultGame);
GoGame.__Rewire__('goGameReducer', reducerStub);
const game = new GoGame();

const actual = game.playMove({ i: 3, j: 3 });

expect(reducerStub).to.have.been.calledWith(game, actions.playMove(3, 3));
expect(actual).to.equal(resultGame);
});
});
});

0 comments on commit 1554ee4

Please sign in to comment.