Skip to content

Commit 9bfa313

Browse files
jest test is finish
1 parent c67c95d commit 9bfa313

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import { getCardValue } from "../implement/3-get-card-value.js";
77

88
test("Valid single-digit card", () => {
99
assert.equal(getCardValue("9♠"), 9);
10-
assert.equal(getCardValue("10♠"), 10);
1110
});
1211

12+
test("Valid double-digit card", () => {
13+
assert.equal(getCardValue("10♠"), 10);
14+
});
1315
test("Ace card", () => {
1416
assert.equal(getCardValue("A♠"), 11);
1517
assert.equal(getCardValue("A♣"), 11);

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,29 @@ 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 number for Valid digit card`, () => {
13+
expect(getCardValue("3♠")).toEqual(3);
14+
});
1215
// Face Cards (J, Q, K)
16+
test(`Should return 10 when given an Face card`, () => {
17+
expect(getCardValue("K♠")).toEqual(10);
18+
});
1319
// Invalid Cards
20+
test(`should return "Input must be a String" when card is not string type`, () => {
21+
expect(() => getCardValue(7)).toThrow("Input must be a String");
22+
});
1423

24+
test(`should return "Expected a number followed by a suit, but got invalid" when card is not string type`, () => {
25+
expect(() => getCardValue("1♠")).toThrow(
26+
"Expected a number followed by a suit, but got invalid"
27+
);
28+
});
29+
30+
test(`should return "Expected a number followed by a suit, but got invalid" when card is not string type`, () => {
31+
expect(() => getCardValue("9X")).toThrow(
32+
"Expected a number followed by a suit, but got invalid"
33+
);
34+
});
1535
// To learn how to test whether a function throws an error as expected in Jest,
1636
// please refer to the Jest documentation:
1737
// https://jestjs.io/docs/expect#tothrowerror
18-

0 commit comments

Comments
 (0)