Skip to content
Open
Changes from all commits
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.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.toHaveBeenCalled();
expect(second).toHaveBeenCalledTimes(1);
});
});