Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
In 2-practice-tdd, added a test in count.test.js
  • Loading branch information
TzeMingHo committed Sep 24, 2025
commit 85587834209ee58c5025d557aca47245fa8a6ca7
7 changes: 7 additions & 0 deletions Sprint-3/2-practice-tdd/count.test.js

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your test case covers the most basic cases - but can you think of some edge cases you should write tests for?

  • what is count is 2.5?
  • what if the count is null or undefined
  • what if the string is an array or an object instead of a string?

Writing tests to cover edge cases will protect your implementation from unexpected situations and make your code more robust.

Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ test("should count multiple occurrences of a character", () => {
// And a character char that does not exist within the case-sensitive str,
// When the function is called with these inputs,
// Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str.

test("should return 0 when character does not exist in the string", () => {
const str = "abcdefg";
const char = "h";
const count = countChar(str, char);
expect(count).toEqual(0);
});