Skip to content

Commit 0d21142

Browse files
committed
rewrite cards test with jest(exercise 3)
1 parent 7c5d0b4 commit 0d21142

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,43 @@ const getCardValue = require("../implement/3-get-card-value");
77
// Case 1: Ace (A)
88
test(`Should return 11 when given an ace card`, () => {
99
expect(getCardValue("A♠")).toEqual(11);
10+
expect(getCardValue("A♥")).toEqual(11);
11+
expect(getCardValue("A♦")).toEqual(11);
12+
expect(getCardValue("A♣")).toEqual(11);
1013
});
1114

1215
// Suggestion: Group the remaining test data into these categories:
13-
// Number Cards (2-10)
14-
// Face Cards (J, Q, K)
16+
// Case 2: Number Cards (2-10)
17+
test(`Should return the number when given a number card`, () => {
18+
expect(getCardValue("2♠")).toEqual(2);
19+
expect(getCardValue("3♦")).toEqual(3);
20+
expect(getCardValue("4♣")).toEqual(4);
21+
expect(getCardValue("5♥")).toEqual(5);
22+
expect(getCardValue("6♠")).toEqual(6);
23+
expect(getCardValue("7♣")).toEqual(7);
24+
expect(getCardValue("8♠")).toEqual(8);
25+
expect(getCardValue("9♦")).toEqual(9);
26+
expect(getCardValue("10♥")).toEqual(10);
27+
});
28+
29+
// Case 3: Face Cards (J, Q, K)
30+
test(`Should return 10 when given a face card`, () => {
31+
expect(getCardValue("J♠")).toEqual(10);
32+
expect(getCardValue("Q♣")).toEqual(10);
33+
expect(getCardValue("K♥")).toEqual(10);
34+
});
35+
1536
// Invalid Cards
37+
test(`Should return an error when given a invalid input`, () => {
38+
expect(() => getCardValue("J♠ ")).toThrow();
39+
expect(() => getCardValue("Q")).toThrow();
40+
expect(() => getCardValue("9♠ ")).toThrow();
41+
expect(() => getCardValue("♠9")).toThrow();
42+
expect(() => getCardValue("♠99")).toThrow();
43+
expect(() => getCardValue("99♠")).toThrow();
44+
expect(() => getCardValue("9❤️")).toThrow();
45+
});
1646

1747
// To learn how to test whether a function throws an error as expected in Jest,
1848
// please refer to the Jest documentation:
1949
// https://jestjs.io/docs/expect#tothrowerror
20-

0 commit comments

Comments
 (0)