Skip to content

Commit 7eab738

Browse files
committed
Write tests in Jest syntax to cover all possible outcomes.
1 parent bc11ec7 commit 7eab738

File tree

1 file changed

+75
-1
lines changed

1 file changed

+75
-1
lines changed

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

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,87 @@ const getCardValue = require("../implement/3-get-card-value");
88
test(`Should return 11 when given an ace card`, () => {
99
expect(getCardValue("A♠")).toEqual(11);
1010
});
11+
test(`Should return 11 when given an ace card`, () => {
12+
expect(getCardValue("A♥")).toEqual(11);
13+
});
14+
test(`Should return 11 when given an ace card`, () => {
15+
expect(getCardValue("A♦")).toEqual(11);
16+
});
17+
test(`Should return 11 when given an ace card`, () => {
18+
expect(getCardValue("A♣")).toEqual(11);
19+
});
1120

1221
// Suggestion: Group the remaining test data into these categories:
1322
// Number Cards (2-10)
23+
test(`Should return 2 when given a 2 card`, () => {
24+
expect(getCardValue("2♠")).toEqual(2);
25+
});
26+
test(`Should return 3 when given a 3 card`, () => {
27+
expect(getCardValue("3♥")).toEqual(3);
28+
});
29+
test(`Should return 4 when given a 4 card`, () => {
30+
expect(getCardValue("4♦")).toEqual(4);
31+
});
32+
test(`Should return 5 when given a 5 card`, () => {
33+
expect(getCardValue("5♣")).toEqual(5);
34+
});
35+
test(`Should return 6 when given a 6 card`, () => {
36+
expect(getCardValue("6♥")).toEqual(6);
37+
});
38+
test(`Should return 7 when given a 7 card`, () => {
39+
expect(getCardValue("7♠")).toEqual(7);
40+
});
41+
test(`Should return 8 when given a 8 card`, () => {
42+
expect(getCardValue("8♦")).toEqual(8);
43+
});
44+
test(`Should return 9 when given a 9 card`, () => {
45+
expect(getCardValue("9♠")).toEqual(9);
46+
});
47+
test(`Should return 10 when given a 10 card`, () => {
48+
expect(getCardValue("10♣")).toEqual(10);
49+
});
50+
1451
// Face Cards (J, Q, K)
52+
test(`Should return 10 when given a J card`, () => {
53+
expect(getCardValue("J♠")).toEqual(10);
54+
});
55+
test(`Should return 10 when given a Q card`, () => {
56+
expect(getCardValue("Q♦")).toEqual(10);
57+
});
58+
test(`Should return 10 when given a K card`, () => {
59+
expect(getCardValue("K♥")).toEqual(10);
60+
});
1561
// Invalid Cards
62+
test(`Should throw an error when given an invalid card`, () => {
63+
expect(() => getCardValue("1♠")).toThrow();
64+
});
65+
test(`Should throw an error when given an invalid card`, () => {
66+
expect(() => getCardValue("2❦")).toThrow();
67+
});
68+
69+
test(`Should throw an error when given an invalid card`, () => {
70+
expect(() => getCardValue("11♥")).toThrow();
71+
});
72+
test(`Should throw an error when given an invalid card`, () => {
73+
expect(() => getCardValue("B♦")).toThrow();
74+
});
75+
test(`Should throw an error when given an invalid card`, () => {
76+
expect(() => getCardValue("Z♣")).toThrow();
77+
});
78+
test(`Should throw an error when given an invalid card`, () => {
79+
expect(() => getCardValue("♣2")).toThrow();
80+
});
81+
test(`Should throw an error when given an invalid card`, () => {
82+
expect(() => getCardValue("s")).toThrow();
83+
});
84+
test(`Should throw an error when given an invalid card`, () => {
85+
expect(() => getCardValue("♣♥♠♦")).toThrow();
86+
});
87+
88+
test(`Should throw an error when given an invalid card`, () => {
89+
expect(() => getCardValue("")).toThrow();
90+
});
1691

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

0 commit comments

Comments
 (0)