test: add tests for isElse function#225
test: add tests for isElse function#225mykhailokurochkin wants to merge 2 commits intomate-academy:masterfrom
Conversation
mykhailokurochkin
commented
Nov 9, 2025
- add tests for ifElse function
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
You've made a great start on the tests for the ifElse function, and it's good that you're checking which callback is executed. However, the tests are currently incomplete and need a couple of additions to be more robust. Specifically, they are missing assertions to verify that the alternative callback is not called, and that all callbacks (condition, first, and second) are invoked with no arguments.
Please update your tests to include these checks. You can use expect(mock).not.toBeCalled() to ensure a function wasn't executed, and expect(mock).toBeCalledWith() to verify it was called with no arguments. These changes are necessary to fully meet the requirements.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| ).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("should call 'first' if condition returns 'true'", () => { |
There was a problem hiding this comment.
This test is a good start, but it doesn't fully verify the behavior. According to the requirements, you should also check that:
- The
secondcallback is not executed when the condition is true. - Both the
conditionandfirstcallbacks are executed with no arguments.
To do this, you could use mock functions for all callbacks and then use assertions like expect(mock).not.toBeCalled() and expect(mock).toBeCalledWith().
| }); | ||
|
|
||
| // write tests here | ||
| it("should call 'second' if condition returns 'false'", () => { |
There was a problem hiding this comment.
Similar to the previous test, this one is incomplete. You need to verify two more things:
- The
firstcallback is not executed when the condition is false. - Both the
conditionandsecondcallbacks are executed with no arguments.
You can use another mock function here as well to assert that it was not called, and check the arguments with toBeCalledWith().
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Excellent work on these tests! I am approving your solution as it successfully meets all the requirements. The test suite is comprehensive and correctly verifies all aspects of the ifElse function's behavior.
I have one small suggestion to make your tests even more robust. In a couple of test cases, ifElse is called with only two arguments. While these tests pass correctly, it's best practice to always call the function with its complete signature. You can simply provide a placeholder empty function, like () => {}, for the unused argument to ensure your tests are consistent and accurately reflect how the function should be used.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| it("should call 'first' without arguments", () => { | ||
| const f = jest.fn(); | ||
|
|
||
| ifElse(() => true, f); |
There was a problem hiding this comment.
While this test passes correctly because the condition is true, the ifElse function is defined to accept three arguments. For consistency and to accurately represent the function's signature, it's best to provide all three arguments, even if one is just a placeholder empty function.
Consider changing this to ifElse(() => true, f, () => {});.