Skip to content

corrections on Jasmine tests #1959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions tests/memory.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,21 @@ describe('MemoryGame', () => {
});

it('should return the shuffled (mixed) array of cards', () => {
const formerCards = memoryGame.cards.map((card) => card.name).toString();
memoryGame.shuffleCards();
const newCards = memoryGame.cards.map((card) => card.name).toString();
expect(formerCards === newCards).toBe(false);
const iterations = 100;
let isShuffled = false;

for (let i = 0; i < iterations; i++) {
const formerCards = [...memoryGame.cards];
memoryGame.shuffleCards();
const newCards = memoryGame.cards;

if (formerCards.some((card, index) => card.name !== newCards[index].name)) {
isShuffled = true;
break;
}
}

expect(isShuffled).toBe(true);
});
});

Expand Down Expand Up @@ -112,11 +123,14 @@ describe('MemoryGame', () => {

it("should return false if there's still some pairs to be guessed", () => {
memoryGame.pairsGuessed = 4;
memoryGame.cards = new Array(16)
expect(memoryGame.checkIfFinished()).toBe(false);
});

it('should return true if all pairs are guessed', () => {
memoryGame.pairsGuessed = 8;
memoryGame.pairsGuessed = 8
memoryGame.pairsClicked = 1;
memoryGame.cards = new Array(16)
expect(memoryGame.checkIfFinished()).toBe(true);
});
});
Expand Down