Skip to content

Commit e8a096f

Browse files
committed
Refactor invalid entry testing using describe
1 parent 6364ddd commit e8a096f

File tree

1 file changed

+18
-52
lines changed

1 file changed

+18
-52
lines changed

Sprint-3/2-practice-tdd/count.test.js

Lines changed: 18 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -26,56 +26,22 @@ test("should count single occurrence of a character", () => {
2626
});
2727

2828
// Scenario 4: Invalid Entries
29-
test(`Should throw an error when given an invalid input`, () => {
30-
expect(() => {
31-
countChar("Courage, the Cowardly Dog", "dog");
32-
}).toThrow();
33-
});
34-
35-
test(`Should throw an error when given an invalid input`, () => {
36-
expect(() => {
37-
countChar("Sheep in the Big City", 1);
38-
}).toThrow();
39-
});
40-
41-
test(`Should throw an error when given an invalid input`, () => {
42-
expect(() => {
43-
countChar(-205, "a");
44-
}).toThrow();
45-
});
46-
47-
test(`Should throw an error when given an invalid input`, () => {
48-
expect(() => {
49-
countChar(-205, 55.5);
50-
}).toThrow();
51-
});
52-
53-
test(`Should throw an error when given an invalid input`, () => {
54-
expect(() => {
55-
countChar(true, "f");
56-
}).toThrow();
57-
});
58-
59-
test(`Should throw an error when given an invalid input`, () => {
60-
expect(() => {
61-
countChar(undefined, "f");
62-
}).toThrow();
63-
});
64-
65-
test(`Should throw an error when given an invalid input`, () => {
66-
expect(() => {
67-
countChar(null, true);
68-
}).toThrow();
69-
});
70-
71-
test(`Should throw an error when given an invalid input`, () => {
72-
expect(() => {
73-
countChar(false, true);
74-
}).toThrow();
75-
});
76-
77-
test(`Should throw an error when given an invalid input`, () => {
78-
expect(() => {
79-
countChar([false], {});
80-
}).toThrow();
29+
const invalidEntries = [
30+
{ a: "Courage, the Cowardly Dog", b: "dog" },
31+
{ a: "Sheep in the Big City", b: 1 },
32+
{ a: -205, b: "a" },
33+
{ a: -205, b: 55.5 },
34+
{ a: true, b: "f" },
35+
{ a: undefined, b: "f" },
36+
{ a: null, b: true },
37+
{ a: false, b: true },
38+
{ a: [false], b: {} },
39+
];
40+
41+
describe.each(invalidEntries)("countChar($a, $b)", ({ a, b }) => {
42+
test(`Should throw an error when given an invalid input (${a}, ${b})`, () => {
43+
expect(() => {
44+
countChar(a, b);
45+
}).toThrow();
46+
});
8147
});

0 commit comments

Comments
 (0)