Skip to content

added unit tests for isElse function#247

Open
Anton-Kuchmasov wants to merge 4 commits intomate-academy:masterfrom
Anton-Kuchmasov:develop
Open

added unit tests for isElse function#247
Anton-Kuchmasov wants to merge 4 commits intomate-academy:masterfrom
Anton-Kuchmasov:develop

Conversation

@Anton-Kuchmasov
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 cover the basic conditional logic. However, I'm requesting a few changes to ensure the tests fully align with the project requirements.

The main issue is that the tests don't verify that the callbacks are called with no arguments, which is a specific requirement. You can easily fix this by updating your assertions. For example, instead of using expect(first).toHaveBeenCalled(), you can use expect(first).toHaveBeenCalledWith() to be more precise.

Please apply this check for the condition, first, and second callbacks in your tests. This will make your test suite more robust and complete.


✨ 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

it('should invoke first cb if truthy contidion', () => {
ifElse(truthyCondition, first, second);

expect(first).toHaveBeenCalled();

Choose a reason for hiding this comment

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

This assertion is correct. To make it more precise according to the requirements, you could also verify that the callback is called with no arguments. You can do this by changing the assertion to expect(first).toHaveBeenCalledWith();.

it('should invoke second cb if falsy condition', () => {
ifElse(falsyCondition, first, second);

expect(second).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, you can make this check more specific by verifying that the second callback is called with no arguments, as required. Using expect(second).toHaveBeenCalledWith(); would accomplish this.

});

it('should invoke one of functions in any case', () => {
falsyCondition.mockReturnValue(!!(Math.random() > 0.5));

Choose a reason for hiding this comment

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

This mock can now return true, which makes the variable name falsyCondition a bit misleading in this test case. It's often clearer to define a new mock for a different behavior. Also, the !! is redundant here, as the comparison Math.random() > 0.5 already results in a boolean.

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 these tests! You're very close to a complete solution. You've correctly added checks to ensure the first and second callbacks are called without arguments.

However, this requires one final change. The tests are still missing a verification that the condition callback is also called with no arguments, which is a core requirement of the task. You can add this assertion to your existing tests for both the truthy and falsy paths using toHaveBeenCalledWith().

Once you add that check, this will be ready for approval!


✨ 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

}).toThrow();
});

it('should invoke first or second functions without args', () => {

Choose a reason for hiding this comment

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

This is a great step forward! You're now correctly checking that first and second are called without arguments.

To fully meet the requirements, you also need to verify that the condition callback is called with no arguments.

A good way to organize this would be to merge these checks into the tests for the truthy and falsy paths. For example, the 'should invoke first cb' test could verify that both truthyCondition and first were called with .toHaveBeenCalledWith(), which would make this separate test case unnecessary.

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 iteration! I am approving your solution. You've successfully addressed the feedback from the previous review by adding the test to verify that the condition callback is called with no arguments. The test suite is now comprehensive and fully covers all requirements. Well done!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

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