|
3 | 3 | const getCardValue = require("../implement/3-get-card-value"); |
4 | 4 |
|
5 | 5 | // TODO: Write tests in Jest syntax to cover all possible outcomes. |
6 | | - |
| 6 | +//["♠", "♥", "♦", "♣"]; |
7 | 7 | // Case 1: Ace (A) |
8 | 8 | test(`Should return 11 when given an ace card`, () => { |
9 | 9 | expect(getCardValue("A♠")).toEqual(11); |
10 | 10 | }); |
11 | | - |
| 11 | +//Case 2: Face Cards(J, Q,K) |
| 12 | +test(`Should return 10 when given a face card`, () => { |
| 13 | + expect(getCardValue("J♠")).toEqual(10); |
| 14 | + expect(getCardValue("K♣")).toEqual(10); |
| 15 | + expect(getCardValue("J♦")).toEqual(10); |
| 16 | +}); |
| 17 | +//case 3: Number Cards (2-10) |
| 18 | +test(`Should return the number when given a number card`, () => { |
| 19 | + expect(getCardValue("4♠")).toEqual(4); |
| 20 | + expect(getCardValue("9♣")).toEqual(9); |
| 21 | + expect(getCardValue("2♦")).toEqual(2); |
| 22 | +}); |
| 23 | +//Case 4: Invalid cards |
| 24 | +test(`Should return the invalid suit, invalid card or invalid card`, () => { |
| 25 | + expect(() => getCardValue("Apple")).toThrow("Invalid card"); |
| 26 | + expect(() => getCardValue("4🎉")).toThrow("Invalid card"); |
| 27 | + expect(() => getCardValue("20♣")).toThrow("Invalid card"); |
| 28 | +}); |
12 | 29 | // Suggestion: Group the remaining test data into these categories: |
13 | 30 | // Number Cards (2-10) |
14 | 31 | // Face Cards (J, Q, K) |
15 | 32 | // Invalid Cards |
16 | 33 |
|
17 | 34 | // To learn how to test whether a function throws an error as expected in Jest, |
18 | 35 | // please refer to the Jest documentation: |
19 | | -// https://jestjs.io/docs/expect#tothrowerror |
20 | | - |
| 36 | +// https://jestjs.io/docs/expecttothrowerror |
0 commit comments