Skip to content

Commit 0ab03d7

Browse files
committed
Adding more tests to Invalid options.
1 parent 5ad5c2a commit 0ab03d7

1 file changed

Lines changed: 36 additions & 4 deletions

File tree

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

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ import { getCardValue } from "../implement/3-get-card-value.js";
77
// // please refer to the Jest documentation:
88
// // https://jestjs.io/docs/expect#tothrowerror
99

10-
// test(`Should throw error "Incorrect suit given" when given wrong symbol"`, () => {
11-
// expect(() => getCardValue("2☺")).toThrow(new Error("Incorrect suit given"));
12-
// });
13-
1410
// test(`Should throw error "Incorrect suit given" when given wrong letter"`, () => {
1511
// expect(() => getCardValue("2K")).toThrow(new Error("Incorrect suit given"));
1612
// });
@@ -83,16 +79,52 @@ test(`Should throw error "Incorrect face given" for face value 11`, () => {
8379
});
8480

8581
// any of 12-99 (double digit number) with valid suit
82+
test(`Should throw error "Incorrect face given" for face value from 12-99`, () => {
83+
expect(() => getCardValue("19♥")).toThrow(new Error("Incorrect face given"));
84+
expect(() => getCardValue("56♥")).toThrow(new Error("Incorrect face given"));
85+
expect(() => getCardValue("77♥")).toThrow(new Error("Incorrect face given"));
86+
expect(() => getCardValue("98♥")).toThrow(new Error("Incorrect face given"));
87+
});
8688

8789
// any B-Z except J/Q/K with valid suit
90+
test(`Should throw error "Incorrect face given" for face value from B-Z expect J/Q/K`, () => {
91+
expect(() => getCardValue("B♥")).toThrow(new Error("Incorrect face given"));
92+
expect(() => getCardValue("G♥")).toThrow(new Error("Incorrect face given"));
93+
expect(() => getCardValue("L♥")).toThrow(new Error("Incorrect face given"));
94+
expect(() => getCardValue("O♥")).toThrow(new Error("Incorrect face given"));
95+
});
8896

8997
// any invalid face with valid suit
98+
test(`Should throw error "Incorrect face given" for any invalid face value with valid suit`, () => {
99+
expect(() => getCardValue("1♥")).toThrow(new Error("Incorrect face given"));
100+
expect(() => getCardValue("G♥")).toThrow(new Error("Incorrect face given"));
101+
expect(() => getCardValue("66♥")).toThrow(new Error("Incorrect face given"));
102+
expect(() => getCardValue("O♥")).toThrow(new Error("Incorrect face given"));
103+
});
90104

91105
// valid suit with valid face (e.g. "♠9")
106+
test(`Should throw error "Incorrect suit given" when suit and face are in wrong order, eg: ♠9`, () => {
107+
expect(() => getCardValue("♠9")).toThrow(new Error("Incorrect suit given"));
108+
expect(() => getCardValue("♦4")).toThrow(new Error("Incorrect suit given"));
109+
expect(() => getCardValue("♠K")).toThrow(new Error("Incorrect suit given"));
110+
expect(() => getCardValue("♥A")).toThrow(new Error("Incorrect suit given"));
111+
});
92112

93113
// any invalid face with any invalid suit
114+
test(`Should throw error "Incorrect suit given" when invalid suit and face are given`, () => {
115+
expect(() => getCardValue("19J")).toThrow(new Error("Incorrect suit given"));
116+
expect(() => getCardValue("14@")).toThrow(new Error("Incorrect suit given"));
117+
expect(() => getCardValue("L$*")).toThrow(new Error("Incorrect suit given"));
118+
expect(() => getCardValue("1B")).toThrow(new Error("Incorrect suit given"));
119+
});
94120

95121
// any of 2-9 (valid single digit number) with invalid suit
122+
test(`Should throw error "Incorrect suit given" when given wrong suit with correct face between 2-9"`, () => {
123+
expect(() => getCardValue("2☺")).toThrow(new Error("Incorrect suit given"));
124+
expect(() => getCardValue("4☺")).toThrow(new Error("Incorrect suit given"));
125+
expect(() => getCardValue("6☺")).toThrow(new Error("Incorrect suit given"));
126+
expect(() => getCardValue("9☺")).toThrow(new Error("Incorrect suit given"));
127+
});
96128

97129
// number 10 (valid double digit number) with invalid suit
98130

0 commit comments

Comments
 (0)