I found that Sinon does not allow you to drown properties, but only methods. I am trying to figure out how to deal with this.
I have the following code:
var Player = { addPoints: function(points) { this.score += points; }, score: 0 } var Game = { setPlayers: function(players) { this.players = players; }, over: function() { return this.players.some(function(player) { return player.score >= 100; }); }, }
Here is the test I wrote:
describe("Game", function() { it("is over if a player has at least 100 points", function() { var game = Object.create(Game); player = Object.create(Player); game.setPlayers([player]); player.addPoints(100); game.over().should.be.true; }); });
I am not good at going in and calling addPoints() on the Player when I test the Game . My initial instinct was to stub Player.points , but I cannot do this because Sinon only mutes properties, not methods.
How should I think about it?
source share