Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
This is a great start, and your tests correctly verify the main conditional logic. However, I'm requesting a change to make your assertions more specific. The requirements state that the condition, first, and second callbacks should be run with no arguments, but the current tests don't verify this.
You can strengthen your tests by using toHaveBeenCalledWith() instead of just toHaveBeenCalled(). This will ensure the callbacks are not only called, but called correctly without any arguments.
For example:
expect(first).toHaveBeenCalledWith();Please apply this check to all the callbacks in your tests.
✨ 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
src/ifElse.test.js
Outdated
| expect(first).toHaveBeenCalled(); | ||
| expect(second).not.toHaveBeenCalled(); |
There was a problem hiding this comment.
These assertions are correct for checking if the functions were called, but they could be more specific. The requirements state that the callbacks should be run with no arguments. You can use toHaveBeenCalledWith() to verify this. It would also be good to assert that the condition function itself was called.
src/ifElse.test.js
Outdated
| expect(second).toHaveBeenCalled(); | ||
| expect(first).not.toHaveBeenCalled(); |
There was a problem hiding this comment.
Similar to the previous test, these assertions could be more precise. The requirements specify that the second callback is called with no arguments. It's a good idea to verify this explicitly using toHaveBeenCalledWith(). Also, consider adding an assertion to ensure the condition function was called.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great job addressing the previous feedback by using toHaveBeenCalledWith()! Your tests are much more specific now and are very close to being complete.
However, one requirement is still not fully tested. The task specifies that the condition callback must also be run with no arguments. Please update your tests in src/ifElse.test.js to verify this for both the true and false scenarios. Adding an expect(condition).toHaveBeenCalledWith() will resolve this.
You're almost there!
✨ 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
| const first = jest.fn(); | ||
| const second = jest.fn(); | ||
|
|
||
| ifElse(condition, first, second); |
There was a problem hiding this comment.
This is a great improvement! To fully meet the requirements, you also need to verify that the condition callback is called with no arguments. Please add an expectation to check this here and in the test case below.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Excellent work on this task! Your tests are very well-written and cover all the requirements perfectly. I am approving your solution so you can continue to the next task, but I have one small suggestion that will make your tests even more precise.
In your tests, you use not.toHaveBeenCalledWith() to check that a callback wasn't run. A more accurate assertion is not.toHaveBeenCalled(). This is because not.toHaveBeenCalled() checks that the function wasn't called at all, which is exactly what we want to confirm in these cases. This is a subtle but important distinction in testing. Great job overall!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| ifElse(condition, first, second); | ||
| expect(condition).toHaveBeenCalledWith(); | ||
| expect(first).toHaveBeenCalledWith(); | ||
| expect(second).not.toHaveBeenCalledWith(); |
There was a problem hiding this comment.
This is a good check. To be even more precise, you can use not.toHaveBeenCalled() here.
not.toHaveBeenCalledWith() checks that the mock was not called with these specific arguments, but it could have been called with others. not.toHaveBeenCalled() asserts that the function was not called at all, which is what we want to verify in this if branch.
|
|
||
| ifElse(condition, first, second); | ||
| expect(condition).toHaveBeenCalledWith(); | ||
| expect(first).not.toHaveBeenCalledWith(); |
There was a problem hiding this comment.
Similar to my other comment, using not.toHaveBeenCalled() would be slightly more accurate here. This ensures the first callback was not invoked at all when the condition is false.
No description provided.