Skip to content

Commit 0deca03

Browse files
committed
get value - jest
1 parent 28b8908 commit 0deca03

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,37 @@ test(`Should return 11 when given an ace card`, () => {
99

1010
// Suggestion: Group the remaining test data into these categories:
1111
// Number Cards (2-10)
12+
test(`should return its numeric value When the card is a number card ("2" to "10")`, () => {
13+
expect(getCardValue("2♠")).toEqual(2);
14+
expect(getCardValue("3♣")).toEqual(3);
15+
expect(getCardValue("4♦")).toEqual(4);
16+
expect(getCardValue("5♠")).toEqual(5);
17+
expect(getCardValue("6♣")).toEqual(6);
18+
expect(getCardValue("7♦")).toEqual(7);
19+
expect(getCardValue("8♠")).toEqual(8);
20+
expect(getCardValue("9♣")).toEqual(9);
21+
});
22+
1223
// Face Cards (J, Q, K)
24+
25+
test("When the card is a face card (J, Q, K), the function should return 10", () => {
26+
expect(getCardValue("J♠")).toEqual(10);
27+
expect(getCardValue("Q♥")).toEqual(10);
28+
expect(getCardValue("K♦")).toEqual(10);
29+
});
30+
1331
// Invalid Cards
1432

33+
test("Invalid card cases", () => {
34+
expect(() => getCardValue("1♠")).toThrow();
35+
expect(() => getCardValue("11♠")).toThrow();
36+
expect(() => getCardValue("X♠")).toThrow();
37+
expect(() => getCardValue("A")).toThrow();
38+
expect(() => getCardValue("2")).toThrow();
39+
expect(() => getCardValue("2X")).toThrow();
40+
expect(() => getCardValue("")).toThrow();
41+
});
42+
1543
// To learn how to test whether a function throws an error as expected in Jest,
1644
// please refer to the Jest documentation:
1745
// https://jestjs.io/docs/expect#tothrowerror
18-

0 commit comments

Comments
 (0)