Skip to content

Commit 3f42554

Browse files
committed
fixing erros in code and including "Incorrect card number" test
1 parent 77cf05b commit 3f42554

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,12 @@ test("Incorrect suit", () => {
2626
"Incorrect suit"
2727
);
2828
});
29+
30+
//Incorrect card value
31+
test("Incorrect card number", () => {
32+
assert.throws(
33+
() => getCardValue("20"),
34+
/Incorrect card number given/,
35+
"Incorrect card number"
36+
);
37+
});

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,7 @@ export function getCardValue(card) {
3939
return 11;
4040
} else if (value >= 2 && value <= 10) {
4141
return value;
42+
} else if (Value > 10) {
43+
throw new Error("Incorrect card number");
4244
}
4345
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ test(`Should return 10 when given a J, Q, K`, () => {
2626

2727
// Invalid Cards
2828
test(`Should throw error 'expected a number followed by a suit, but got "invalid"' with invalid card`, () => {
29-
expect(() => getCardValue("12♥")).toThrow;
29+
expect(() => getCardValue("120♥")).toThrow;
3030
new Error('expected a number followed by a suit, but got "invalid"');
31-
expect(() => getCardValue("20♦")).toThrow;
31+
expect(() => getCardValue("203♦")).toThrow;
3232
new Error('expected a number followed by a suit, but got "invalid"');
3333
});
3434
// To learn how to test whether a function throws an error as expected in Jest,

0 commit comments

Comments
 (0)