-
Notifications
You must be signed in to change notification settings - Fork 0
/
guessing-game.test.js
35 lines (28 loc) · 949 Bytes
/
guessing-game.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const { mockRandom } = require("jest-mock-random");
const { guessingGame } = require("./guessing-game");
describe("guessingGame", function() {
let game;
// force the random number to always be the same
mockRandom(0.6);
beforeEach(function() {
game = guessingGame();
});
it("returns a function", function() {
expect(game).toBeInstanceOf(Function);
});
it("tells you when your guess is too low", function() {
expect(game(10)).toBe("10 is too low!");
});
it("tells you when your guess is too high", function() {
expect(game(80)).toBe("80 is too high!");
});
it("tells you when your guess is correct, along with the number of guesses.", function() {
game(55);
game(65);
expect(game(60)).toBe("You win! You found 60 in 3 guesses.");
});
it("stops you from guessing when the game is over", function() {
game(60);
expect(game(60)).toBe("The game is over, you already won!");
});
});