Skip to content

Commit 21048fe

Browse files
committed
Tests for zero, single, and multuple occurrences. Invvalid edge case tests included
1 parent 7816f8b commit 21048fe

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,58 @@ test("should count single occurrence of a character", () => {
2424
expect(countChar("Angela Bassett", "r")).toEqual(0);
2525
expect(countChar("Better Off Ted", "9")).toEqual(0);
2626
});
27+
28+
// 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();
81+
});

0 commit comments

Comments
 (0)