我發現Sinon不會讓你存根屬性,只有方法。我試圖找出如何處理/擁抱這個。我應該如何避免使用Sinon.js的存根屬性
我有以下代碼:
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;
});
},
}
這裏有一個測試,我寫道:
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;
});
});
感覺錯了我一定要進去,並呼籲addPoints()
上Player
當我測試Game
。我最初的本能是存根Player.points
,但我不能這樣做,因爲Sinon只存根屬性,而不是方法。
我應該如何思考這個問題?
謝謝 - 這在回顧過程中顯得很明顯。 – michael