Skip to content

Commit b290716

Browse files
committed
added test for correct amount of arguments and amended function to reflect this
1 parent 2958939 commit b290716

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
function countChar(stringOfCharacters, findCharacter) {
2+
if (arguments.length !== 2) {
3+
throw new Error(
4+
"Function requires exactly two arguments: a string and a character to find."
5+
);
6+
}
27
if (typeof stringOfCharacters !== 'string'){
38
throw new Error("First argument must be a string.");
49
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,14 @@ test.each([
103103
countChar(str, char);
104104
}).toThrow(error);
105105
});
106+
//test for 2 arguments
107+
test("should throw error if more/less than 2 arguments are provided", () => {
108+
expect(() => {
109+
countChar("hello");
110+
}).toThrow("Function requires exactly two arguments: a string and a character to find.");
111+
expect(() => {
112+
countChar("hello", "h", "extra");
113+
}).toThrow(
114+
"Function requires exactly two arguments: a string and a character to find."
115+
);
116+
});

0 commit comments

Comments
 (0)