Skip to content

Commit

Permalink
test: amend Jest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dvfrancis committed Oct 29, 2024
1 parent 239b0d2 commit 2025b0b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
14 changes: 8 additions & 6 deletions assets/scripts/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ function displayPoints() {
function decideAces() {
let acesBool = Math.random() < 0.5;
let acesResult = acesBool ? "HIGH" : "LOW";
amendCardsObject(acesResult);
acesValue = acesResult;
amendCardsObject(acesResult);
}

/**
Expand Down Expand Up @@ -168,7 +168,7 @@ function displayModal() {
messageModal.style.display = "block";
messageModal.classList.add("show");
} else {
console.error("Modal element not found");
// console.error("Modal element not found");
}
}

Expand All @@ -179,7 +179,7 @@ function deleteModal() {
if (messageModal) {
messageModal.remove();
} else {
console.error("Modal element not found");
// console.error("Modal element not found");
}
}

Expand All @@ -204,7 +204,7 @@ async function shuffleCards() {
deckUrl = cardDeck.deck_id;
drawCards();
} catch (error) {
console.error('Fetch error:', error);
// console.error('Fetch error:', error);
}
}

Expand Down Expand Up @@ -243,7 +243,7 @@ async function drawCards() {
displayCard();
getWager();
} catch (error) {
console.error('Fetch error:', error);
// console.error('Fetch error:', error);
}
}

Expand Down Expand Up @@ -597,5 +597,7 @@ function leaveGame(url) {
shuffleCards();

module.exports = {
leaveGame
leaveGame,
decideAces,
amendCardsObject
}
8 changes: 4 additions & 4 deletions assets/scripts/tests/game.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
describe('gameplay', () => {
beforeEach(() => {
document.body.innerHTML = '<input type="submit" id="play-game" value="PLAY">'; // Create mock DOM element for testing
delete window.location; // Remove current window object
document.body.innerHTML = '<input type="submit" id="play-game" value="PLAY">';
delete window.location;
window.location = {
href: ''
}; // Create mock window object
};
});

test("leaveGame function should navigate to specified URL", () => {
const {
leaveGame
} = require('../game'); // Import JavaScript file
} = require('../game');
const testUrl = "index.html";
leaveGame(testUrl);
expect(window.location.href).toBe(testUrl);
Expand Down

0 comments on commit 2025b0b

Please sign in to comment.