Skip to content

test: add tests for isElse function#225

Open
mykhailokurochkin wants to merge 2 commits intomate-academy:masterfrom
mykhailokurochkin:develop
Open

test: add tests for isElse function#225
mykhailokurochkin wants to merge 2 commits intomate-academy:masterfrom
mykhailokurochkin:develop

Conversation

@mykhailokurochkin
Copy link

  • add tests for ifElse function

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

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

).toBeUndefined();
});

it("should call 'first' if condition returns 'true'", () => {

Choose a reason for hiding this comment

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

This test is a good start, but it doesn't fully verify the behavior. According to the requirements, you should also check that:

  1. The second callback is not executed when the condition is true.
  2. Both the condition and first callbacks 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'", () => {

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, this one is incomplete. You need to verify two more things:

  1. The first callback is not executed when the condition is false.
  2. Both the condition and second callbacks 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().

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! 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

  1. Rate AI review example

it("should call 'first' without arguments", () => {
const f = jest.fn();

ifElse(() => true, f);

Choose a reason for hiding this comment

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

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, () => {});.

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