Skip to content

Commit e59ab40

Browse files
authored
Rewrite tests for getCardValue using Jest
1 parent a9c0735 commit e59ab40

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,31 @@ test(`Should return 11 when given an ace card`, () => {
99
expect(getCardValue("A♠")).toEqual(11);
1010
});
1111

12-
// Suggestion: Group the remaining test data into these categories:
13-
// Number Cards (2-10)
14-
// Face Cards (J, Q, K)
15-
// Invalid Cards
12+
// Number cards (2–10)
13+
test('returns correct numeric values for number cards', () => {
14+
expect(getCardValue("2♠")).toEqual(2);
15+
expect(getCardValue("5♥")).toEqual(5);
16+
expect(getCardValue("9♦")).toEqual(9);
17+
expect(getCardValue("10♣")).toEqual(10);
18+
});
19+
20+
// Face cards
21+
test('returns 10 for face cards', () => {
22+
expect(getCardValue("J♠")).toEqual(10);
23+
expect(getCardValue("Q♥")).toEqual(10);
24+
expect(getCardValue("K♦")).toEqual(10);
25+
});
1626

27+
// Ace
28+
test('returns 11 for Ace', () => {
29+
expect(getCardValue("A♣")).toEqual(11);
30+
});
31+
32+
// Invalid cards
33+
test('invalid card strings should throw an error', () => {
34+
expect(() => getCardValue("A")).toThrow();
35+
expect(() => getCardValue("B")).toThrow();
36+
});
1737
// To learn how to test whether a function throws an error as expected in Jest,
1838
// please refer to the Jest documentation:
1939
// https://jestjs.io/docs/expect#tothrowerror

0 commit comments

Comments
 (0)