Skip to content

Commit 075e91a

Browse files
committed
add Jest tests for getCardValue
1 parent 478afbb commit 075e91a

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
import { getCardValue } from "../implement/3-get-card-value.js";
22

3-
// TODO: Write tests in Jest syntax to cover all possible outcomes.
4-
5-
// Case 1: Ace (A)
63
test(`Should return 11 when given an ace card`, () => {
74
expect(getCardValue("A♠")).toEqual(11);
5+
expect(getCardValue("A♥")).toEqual(11);
86
});
97

10-
// Suggestion: Group the remaining test data into these categories:
11-
// Number Cards (2-10)
12-
// Face Cards (J, Q, K)
13-
// Invalid Cards
8+
test(`Should return the number for number cards`, () => {
9+
expect(getCardValue("2♣")).toEqual(2);
10+
expect(getCardValue("5♥")).toEqual(5);
11+
expect(getCardValue("7♠")).toEqual(7);
12+
expect(getCardValue("10♦")).toEqual(10);
13+
});
1414

15-
// To learn how to test whether a function throws an error as expected in Jest,
16-
// please refer to the Jest documentation:
17-
// https://jestjs.io/docs/expect#tothrowerror
15+
test(`Should return 10 for face cards`, () => {
16+
expect(getCardValue("J♠")).toEqual(10);
17+
expect(getCardValue("Q♥")).toEqual(10);
18+
expect(getCardValue("K♦")).toEqual(10);
19+
});
1820

21+
test(`Should throw for invalid cards`, () => {
22+
expect(() => getCardValue("A")).toThrow();
23+
expect(() => getCardValue("♠")).toThrow();
24+
expect(() => getCardValue("11♠")).toThrow();
25+
expect(() => getCardValue("hello")).toThrow();
26+
expect(() => getCardValue("")).toThrow();
27+
expect(() => getCardValue("A♠♠")).toThrow();
28+
});

0 commit comments

Comments
 (0)