Skip to content

Commit 21b43b0

Browse files
implement more test cases with Jest for exercise 3-get-card-value.test
1 parent 7364607 commit 21b43b0

1 file changed

Lines changed: 25 additions & 26 deletions

File tree

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

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,46 @@ import { getCardValue } from "../implement/3-get-card-value.js";
55

66
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
77

8+
import { getCardValue } from "../implement/1-get-card-value.js";
9+
810
test("Valid single-digit card", () => {
9-
assert.equal(getCardValue("9♠"), 9);
11+
expect(getCardValue("9♠")).toEqual(9);
1012
});
1113

1214
test("Arbitrary non-card string", () => {
13-
assert.throws(
14-
() => getCardValue("invalid"),
15-
/Expected a number followed by a suit, but got "invalid"/,
16-
"Expected clear error"
15+
expect(() => getCardValue("invalid")).toThrow(
16+
'Expected a number followed by a suit, but got "invalid"'
1717
);
1818
});
1919

20-
// TODO: What other invalid card cases can you think of?
2120
test("Ace returns 11", () => {
22-
assert.equal(getCardValue("A♠"), 11);
21+
expect(getCardValue("A♠")).toEqual(11);
2322
});
2423

2524
test("Number card returns its numeric value", () => {
26-
assert.equal(getCardValue("2♥"), 2);
27-
assert.equal(getCardValue("7♦"), 7);
28-
assert.equal(getCardValue("10♣"), 10);
25+
expect(getCardValue("2♥")).toEqual(2);
26+
expect(getCardValue("7♦")).toEqual(7);
27+
expect(getCardValue("10♣")).toEqual(10);
2928
});
3029

3130
test("Face cards return 10", () => {
32-
assert.equal(getCardValue("J♣"), 10);
33-
assert.equal(getCardValue("Q♦"), 10);
34-
assert.equal(getCardValue("K♥"), 10);
31+
expect(getCardValue("J♣")).toEqual(10);
32+
expect(getCardValue("Q♦")).toEqual(10);
33+
expect(getCardValue("K♥")).toEqual(10);
3534
});
3635

3736
test("Invalid format throws an error", () => {
38-
assert.throws(() => getCardValue("A★"), Error);
39-
assert.throws(() => getCardValue("11♠"), Error);
40-
assert.throws(() => getCardValue("X♥"), Error);
41-
assert.throws(() => getCardValue("A"), Error);
42-
assert.throws(() => getCardValue("♠A"), Error);
43-
assert.throws(() => getCardValue(" A♠"), Error);
44-
assert.throws(() => getCardValue("A♠♠"), Error);
45-
assert.throws(() => getCardValue(undefined), Error);
46-
assert.throws(() => getCardValue(null), Error);
47-
assert.throws(() => getCardValue(""), Error);
48-
assert.throws(() => getCardValue("a♠"), Error);
49-
assert.throws(() => getCardValue("k♥"), Error);
50-
assert.throws(() => getCardValue("q♦"), Error);
37+
expect(() => getCardValue("A★")).toThrow(Error);
38+
expect(() => getCardValue("11♠")).toThrow(Error);
39+
expect(() => getCardValue("X♥")).toThrow(Error);
40+
expect(() => getCardValue("A")).toThrow(Error);
41+
expect(() => getCardValue("♠A")).toThrow(Error);
42+
expect(() => getCardValue(" A♠")).toThrow(Error);
43+
expect(() => getCardValue("A♠♠")).toThrow(Error);
44+
expect(() => getCardValue(undefined)).toThrow(Error);
45+
expect(() => getCardValue(null)).toThrow(Error);
46+
expect(() => getCardValue("")).toThrow(Error);
47+
expect(() => getCardValue("a♠")).toThrow(Error);
48+
expect(() => getCardValue("k♥")).toThrow(Error);
49+
expect(() => getCardValue("q♦")).toThrow(Error);
5150
});

0 commit comments

Comments
 (0)