Skip to content

Commit 1a0087d

Browse files
committed
verify error messages in getCardValue tests per reviewer feedback
1 parent ad3a9e6 commit 1a0087d

2 files changed

Lines changed: 46 additions & 13 deletions

File tree

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

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,32 @@ test("Number cards return their value", () => {
3434
});
3535

3636
test("Invalid cards throw an error", () => {
37-
assert.throws(() => getCardValue("A"));
38-
assert.throws(() => getCardValue("♠"));
39-
assert.throws(() => getCardValue("11♠"));
40-
assert.throws(() => getCardValue("1♠"));
41-
assert.throws(() => getCardValue("hello"));
42-
assert.throws(() => getCardValue(""));
43-
assert.throws(() => getCardValue("A♠♠"));
37+
assert.throws(
38+
() => getCardValue("A"),
39+
/Expected a number followed by a suit, but got "A"/
40+
);
41+
assert.throws(
42+
() => getCardValue("♠"),
43+
/Expected a number followed by a suit, but got "♠"/
44+
);
45+
assert.throws(
46+
() => getCardValue("11♠"),
47+
/Expected a number followed by a suit, but got "11♠"/
48+
);
49+
assert.throws(
50+
() => getCardValue("1♠"),
51+
/Expected a number followed by a suit, but got "1♠"/
52+
);
53+
assert.throws(
54+
() => getCardValue("hello"),
55+
/Expected a number followed by a suit, but got "hello"/
56+
);
57+
assert.throws(
58+
() => getCardValue(""),
59+
/Expected a number followed by a suit, but got ""/
60+
);
61+
assert.throws(
62+
() => getCardValue("A♠♠"),
63+
/Expected a number followed by a suit, but got "A♠♠"/
64+
);
4465
});

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,22 @@ test(`Should return 10 for face cards`, () => {
1919
});
2020

2121
test(`Should throw for invalid cards`, () => {
22-
expect(() => getCardValue("A")).toThrow();
23-
expect(() => getCardValue("♠")).toThrow();
24-
expect(() => getCardValue("11♠")).toThrow();
25-
expect(() => getCardValue("hello")).toThrow();
26-
expect(() => getCardValue("")).toThrow();
27-
expect(() => getCardValue("A♠♠")).toThrow();
22+
expect(() => getCardValue("A")).toThrow(
23+
/Expected a number followed by a suit, but got "A"/
24+
);
25+
expect(() => getCardValue("♠")).toThrow(
26+
/Expected a number followed by a suit, but got "♠"/
27+
);
28+
expect(() => getCardValue("11♠")).toThrow(
29+
/Expected a number followed by a suit, but got "11♠"/
30+
);
31+
expect(() => getCardValue("hello")).toThrow(
32+
/Expected a number followed by a suit, but got "hello"/
33+
);
34+
expect(() => getCardValue("")).toThrow(
35+
/Expected a number followed by a suit, but got ""/
36+
);
37+
expect(() => getCardValue("A♠♠")).toThrow(
38+
/Expected a number followed by a suit, but got "A♠♠"/
39+
);
2840
});

0 commit comments

Comments
 (0)