|
1 | | -// This statement loads the getCardValue function you wrote in the implement directory. |
2 | | -// We will use the same function, but write tests for it using Jest in this file. |
3 | | -const getCardValue = require("../implement/3-get-card-value"); |
4 | | - |
5 | | -// TODO: Write tests in Jest syntax to cover all possible outcomes. |
6 | 1 |
|
7 | 2 | // Case 1: Ace (A) |
8 | | -test(`Should return 11 when given an ace card`, () => { |
| 3 | +test("should return 11 when given an ace card", () => { |
9 | 4 | expect(getCardValue("A♠")).toEqual(11); |
10 | 5 | }); |
11 | 6 |
|
12 | | -// Suggestion: Group the remaining test data into these categories: |
13 | | -// Number Cards (2-10) |
14 | | -// Face Cards (J, Q, K) |
15 | | -// Invalid Cards |
| 7 | +// Case 2: Number cards (2-10) |
| 8 | +test("should return the numeric value for number cards", () => { |
| 9 | + expect(getCardValue("2♥")).toEqual(2); |
| 10 | + expect(getCardValue("5♣")).toEqual(5); |
| 11 | + expect(getCardValue("9♦")).toEqual(9); |
| 12 | + expect(getCardValue("10♠")).toEqual(10); |
| 13 | +}); |
16 | 14 |
|
17 | | -// To learn how to test whether a function throws an error as expected in Jest, |
18 | | -// please refer to the Jest documentation: |
19 | | -// https://jestjs.io/docs/expect#tothrowerror |
| 15 | +// Case 3: Face cards (J, Q, K) |
| 16 | +test("should return 10 for face cards", () => { |
| 17 | + expect(getCardValue("J♠")).toEqual(10); |
| 18 | + expect(getCardValue("Q♥")).toEqual(10); |
| 19 | + expect(getCardValue("K♦")).toEqual(10); |
| 20 | +}); |
| 21 | + |
| 22 | +// Case 4: Invalid cards |
| 23 | +test("should throw an error for invalid cards", () => { |
| 24 | + expect(() => getCardValue("invalid")).toThrow(); |
| 25 | + expect(() => getCardValue("1♠")).toThrow(); |
| 26 | + expect(() => getCardValue("11♠")).toThrow(); |
| 27 | + expect(() => getCardValue("A")).toThrow(); |
| 28 | + expect(() => getCardValue("♠")).toThrow(); |
| 29 | + expect(() => getCardValue("KH")).toThrow(); |
| 30 | + expect(() => getCardValue("")).toThrow(); |
| 31 | +}); |
20 | 32 |
|
0 commit comments