Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great work on the tests for the ifElse function! The structure is solid and you're correctly verifying which callback gets executed. However, I am requesting a change because the tests are missing a key requirement from the task description. The tests need to verify that all callbacks (condition, first, and second) are called with no arguments.
You can easily add this check by updating your assertions to use Jest's toHaveBeenCalledWith() matcher. For example:
expect(condition).toHaveBeenCalledWith();Please add this verification for all callbacks in the relevant tests 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
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Excellent work on this submission! I am approving your solution as you have successfully met all the core requirements. You did a great job addressing the previous feedback by adding checks to ensure all callbacks are called with no arguments.
As a suggestion for future improvement, your new test case in src/ifElse.test.js handles multiple scenarios (both true and false conditions) at once. It's a best practice for each test to focus on a single behavior, as this makes them easier to read and debug. A cleaner approach would be to integrate the toHaveBeenCalledWith() checks into your existing, more specific tests for the true and false paths.
This is just a recommendation to help you write even more maintainable tests in the future, not a required change. Fantastic job!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| it('should call all the callbacks with no arguments', () => { | ||
| const condition1 = jest.fn(() => false); | ||
| const condition2 = jest.fn(() => true); | ||
| const first = jest.fn(); | ||
| const second = jest.fn(); | ||
|
|
||
| expect(ifElse(condition1, first, second)).toBeUndefined(); | ||
|
|
||
| expect(condition1).toHaveBeenCalledTimes(1); | ||
| expect(condition1).toHaveBeenCalledWith(); | ||
| expect(second).toHaveBeenCalledTimes(1); | ||
| expect(second).toHaveBeenCalledWith(); | ||
|
|
||
| expect(ifElse(condition2, first, second)).toBeUndefined(); | ||
|
|
||
| expect(condition2).toHaveBeenCalledTimes(1); | ||
| expect(condition2).toHaveBeenCalledWith(); | ||
| expect(first).toHaveBeenCalledTimes(1); | ||
| expect(first).toHaveBeenCalledWith(); | ||
| }); |
There was a problem hiding this comment.
Great job adding the checks to ensure callbacks are called with no arguments! You've correctly addressed the main point from the previous review.
However, this single test case is doing too much by testing both the false and true paths for the condition. It's a best practice for each it block to test only one specific scenario. This makes tests easier to read and debug if they fail.
A better approach would be to integrate these toHaveBeenCalledWith() checks into your existing, more specific tests and then remove this one. For example:
- In the test
'should call the first function...', you can addexpect(first).toHaveBeenCalledWith(). - In the test
'should call the second function...', you can addexpect(second).toHaveBeenCalledWith().
No description provided.