Skip to content

Commit abd236e

Browse files
committed
get card value jest
1 parent 6f96975 commit abd236e

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

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

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,64 @@
22
// We will use the same function, but write tests for it using Jest in this file.
33
const getCardValue = require("../implement/3-get-card-value");
44

5+
56
// TODO: Write tests in Jest syntax to cover all possible outcomes.
67

8+
79
// Case 1: Ace (A)
810
test(`Should return 11 when given an ace card`, () => {
911
expect(getCardValue("A♠")).toEqual(11);
1012
});
1113

14+
1215
// Suggestion: Group the remaining test data into these categories:
1316
// Number Cards (2-10)
1417
// Face Cards (J, Q, K)
1518
// Invalid Cards
1619

20+
1721
// To learn how to test whether a function throws an error as expected in Jest,
1822
// please refer to the Jest documentation:
19-
// https://jestjs.io/docs/expect#tothrowerror
23+
// [https://jestjs.io/docs/expect#tothrowerror](https://jestjs.io/docs/expect#tothrowerror)
24+
25+
26+
// Number Cards (2–10)
27+
test(`Should return 2 when given "2♦"`, () => {
28+
expect(getCardValue("2♦")).toEqual(2);
29+
});
30+
31+
test(`Should return 5 when given "5♣"`, () => {
32+
expect(getCardValue("5♣")).toEqual(5);
33+
});
34+
35+
test(`Should return 10 when given "10♥"`, () => {
36+
expect(getCardValue("10♥")).toEqual(10);
37+
});
38+
2039

40+
// Face Cards (J, Q, K)
41+
test(`Should return 10 when given "J♣"`, () => {
42+
expect(getCardValue("J♣")).toEqual(10);
43+
});
44+
45+
test(`Should return 10 when given "Q♦"`, () => {
46+
expect(getCardValue("Q♦")).toEqual(10);
47+
});
48+
49+
test(`Should return 10 when given "K♥"`, () => {
50+
expect(getCardValue("K♥")).toEqual(10);
51+
});
52+
53+
54+
// Invalid Cards
55+
test(`Should throw an error when given an invalid card symbol like "Z♠"`, () => {
56+
expect(() => getCardValue("Z♠")).toThrowError();
57+
});
58+
59+
test(`Should throw an error when given an empty string`, () => {
60+
expect(() => getCardValue("")).toThrowError();
61+
});
62+
63+
test(`Should throw an error when given null`, () => {
64+
expect(() => getCardValue(null)).toThrowError();
65+
});

0 commit comments

Comments
 (0)