Skip to content

Add solution#244

Open
dminikulin wants to merge 3 commits intomate-academy:masterfrom
dminikulin:develop
Open

Add solution#244
dminikulin wants to merge 3 commits intomate-academy:masterfrom
dminikulin:develop

Conversation

@dminikulin
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines +24 to +25
expect(first).toHaveBeenCalled();
expect(second).not.toHaveBeenCalled();

Choose a reason for hiding this comment

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

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.

Comment on lines +34 to +35
expect(second).toHaveBeenCalled();
expect(first).not.toHaveBeenCalled();

Choose a reason for hiding this comment

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

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.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

const first = jest.fn();
const second = jest.fn();

ifElse(condition, first, second);

Choose a reason for hiding this comment

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

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.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

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

  1. Rate AI review example

ifElse(condition, first, second);
expect(condition).toHaveBeenCalledWith();
expect(first).toHaveBeenCalledWith();
expect(second).not.toHaveBeenCalledWith();

Choose a reason for hiding this comment

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

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();

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants