Skip to content

Commit b5fc39c

Browse files
authored
rewrite tests with jests complete
Added Jest tests for card value function covering Aces, face cards, number cards, and invalid cards.
1 parent 18524d2 commit b5fc39c

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,34 @@
33
const getCardValue = require("../implement/3-get-card-value");
44

55
// TODO: Write tests in Jest syntax to cover all possible outcomes.
6-
6+
//["♠", "♥", "♦", "♣"];
77
// Case 1: Ace (A)
88
test(`Should return 11 when given an ace card`, () => {
99
expect(getCardValue("A♠")).toEqual(11);
1010
});
11-
11+
//Case 2: Face Cards(J, Q,K)
12+
test(`Should return 10 when given a face card`, () => {
13+
expect(getCardValue("J♠")).toEqual(10);
14+
expect(getCardValue("K♣")).toEqual(10);
15+
expect(getCardValue("J♦")).toEqual(10);
16+
});
17+
//case 3: Number Cards (2-10)
18+
test(`Should return the number when given a number card`, () => {
19+
expect(getCardValue("4♠")).toEqual(4);
20+
expect(getCardValue("9♣")).toEqual(9);
21+
expect(getCardValue("2♦")).toEqual(2);
22+
});
23+
//Case 4: Invalid cards
24+
test(`Should return the invalid suit, invalid card or invalid card`, () => {
25+
expect(() => getCardValue("Apple")).toThrow("Invalid card");
26+
expect(() => getCardValue("4🎉")).toThrow("Invalid card");
27+
expect(() => getCardValue("20♣")).toThrow("Invalid card");
28+
});
1229
// Suggestion: Group the remaining test data into these categories:
1330
// Number Cards (2-10)
1431
// Face Cards (J, Q, K)
1532
// Invalid Cards
1633

1734
// To learn how to test whether a function throws an error as expected in Jest,
1835
// please refer to the Jest documentation:
19-
// https://jestjs.io/docs/expect#tothrowerror
20-
36+
// https://jestjs.io/docs/expecttothrowerror

0 commit comments

Comments
 (0)