Skip to content

Commit 72b3282

Browse files
committed
added tests, edited script.js to make tests work
1 parent 7fb6e49 commit 72b3282

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

assets/js/script.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
const listOfNodes = Array.from(document.querySelectorAll('.node'));
2-
const highScoreRef = document.querySelector('#highscore');
3-
const maxLengthRef = document.querySelector('#maxlength');
42

53
/**
64
* The game's settings.
@@ -142,6 +140,10 @@ const playerTurn = () => {
142140
};
143141
} else {
144142
alert("BZZT. From the top.");
143+
144+
const highScoreRef = document.querySelector('#highscore');
145+
const maxLengthRef = document.querySelector('#maxlength');
146+
145147
if (highScoreRef.innerHTML < gameConfig.score) {
146148
highScoreRef.innerHTML = gameConfig.score;
147149
};

assets/js/tests/script.test.js

+16
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,20 @@ describe("gameplay is functioning properly", () => {
142142
test("turnTime should be reduced by 100", () => {
143143
expect(gameConfig.turnTime).toEqual(300);
144144
});
145+
});
146+
147+
describe("scores are updating properly", () => {
148+
beforeAll(() => {
149+
gameConfig.patternCount = 7;
150+
gameConfig.currentPat = [4, 6, 1, 7, 2, 3, 5];
151+
gameConfig.playerInput = [4, 6, 1, 7, 2, 3, 2];
152+
gameConfig.score = 27;
153+
});
154+
test("high score is correctly updated", () => {
155+
playerTurn();
156+
expect(document.querySelector('#highscore').innerHTML).toBe("27");
157+
});
158+
test("max length is correctly updated", () => {
159+
expect(document.querySelector('#maxlength').innerHTML).toBe("7");
160+
});
145161
});

0 commit comments

Comments
 (0)