A fascinating challenge I've taken on involves testing a card game created in JavaScript using Jest.
Currently, I have developed two tests: one to verify the creation of a 52-card deck and another to confirm that the player is dealt two cards at the beginning of the game:
const { Deck, Player} = require("./cardgame")
let deck = new Deck()
deck = deck.createDeck()
let player = new Player()
player.openinghand(deck)
test('Expecting the Deck to contain 52 cards', () => {
expect(deck.length).toBe(52);
});
test('Expecting the opening hand of the player to consist of 2 cards', () => {
expect(player.hand.length).toBe(2)
});
Upon running the tests, only the second one passes. The failure of the first test can be attributed to the fact that the deck length does not remain at 52 throughout the process. Does Jest execute all tests simultaneously rather than in the order they are written? How can I adjust my approach to ensure both tests pass successfully?