I'm making a ten pin bowling game and to test the bonus points feature I would like to pass in a list of hard coded outcomes (pinsHit) for each roll. Main constructor functions are Game, Frame and Roll.
Since bonuses are awarded by doubling the points of two subsequent rolls for strikes (10 pins hit first roll of frame) and doubling the points of one subsequent roll for spares (10 pins by end of frame(2 rolls)), we need to calculate it in Game at the end of all 10 frames, because Game stores all the frames and their properties (points, strike/spare?) and can loop for it with hindsight. (Have added this info for context as this question got tumbleweed badge so now you see why I expect 40 for game._score
Unfortunately I cannot stub Roll#outcome
with Jasmine's returnValues
because Roll#outcome
is buried like 3 functions deep (playArgTimes calls play calls roll calls outcome).
Another way would be if Jasmine had a method like passValues
which allowed me to do something like spyOn(game, "play").and.passValues()
because the play method actually allows for the hard coding of the roll outcome by passing that outcome as a parameter.
I was thinking this might be a good time to write a custom function but I literally have no idea of where to start for this one, I'm new to programming. Any ideas on next steps? Am I missing something obvious?
My test:
it('adds bonuses to points', function(){
spyOn(roll, "outcome").and.returnValues(10,3,4,9,1,2,2); //roll is buried too deep to stub
helperModule.playArgTimes(4,game);
game.bonusCalc();
game.updateScore();
expect(game._score).toEqual(40);
});