Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions src/ifElse.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
'use strict';

describe('ifElse', () => {
// const { ifElse } = require('./ifElse');
const { ifElse } = require('./ifElse');
let conditionTrue;
let conditionFalse;
let first;
let second;

it('should ', () => {
beforeEach(() => {
conditionTrue = jest.fn(() => true);
conditionFalse = jest.fn(() => false);
first = jest.fn();
second = jest.fn();
});

afterEach(() => {
conditionTrue.mockRestore();
conditionFalse.mockRestore();
first.mockRestore();
second.mockRestore();
});

it('should return noting', () => {

Choose a reason for hiding this comment

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

There's a small typo in the test description. It should be 'nothing' instead of 'noting'.

Choose a reason for hiding this comment

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

There's a small typo in the test description. It should probably be "nothing" instead of "noting".

expect(ifElse(conditionTrue, first, second)).toBeUndefined();
});

it('should pass first fuction if condition is true', () => {

Choose a reason for hiding this comment

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

There's a typo in the test description. It should be 'function' instead of 'fuction'.

ifElse(conditionTrue, first, second);

expect(conditionTrue).toHaveBeenCalledTimes(1);
expect(first).toHaveBeenCalledTimes(1);
expect(second).not.toHaveBeenCalledTimes;

Check failure on line 33 in src/ifElse.test.js

View workflow job for this annotation

GitHub Actions / build (12.x)

Expected an assignment or function call and instead saw an expression

Choose a reason for hiding this comment

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

This assertion is incorrect and will not work as expected. toHaveBeenCalledTimes is a function and must be called with an argument, like toHaveBeenCalledTimes(0). The simpler way to check if a function was not called is expect(second).not.toHaveBeenCalled().

});

// write tests here
it('should pass first fuction if condition is false', () => {

Choose a reason for hiding this comment

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

This test description is misleading and contains a typo. This test case verifies that the second function is called when the condition is false, not the first function. A clearer description would be something like 'should call second function if condition is false'.

Choose a reason for hiding this comment

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

This test description seems a bit misleading. While the test itself is correct, the description says it should pass the "first function", but it actually verifies that the second function is called when the condition is false. Updating the description to something like "should call the second function if the condition is false" would make it clearer.

ifElse(conditionFalse, first, second);

expect(conditionFalse).toHaveBeenCalledTimes(1);
expect(first).not.toHaveBeenCalledTimes;

Check failure on line 40 in src/ifElse.test.js

View workflow job for this annotation

GitHub Actions / build (12.x)

Expected an assignment or function call and instead saw an expression

Choose a reason for hiding this comment

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

This assertion is also incorrect, similar to the one in the previous test. toHaveBeenCalledTimes needs to be called as a function. To check that the first function was not called, please use expect(first).not.toHaveBeenCalled().

expect(second).toHaveBeenCalledTimes(1);
});
});
Loading