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
67 changes: 64 additions & 3 deletions src/ifElse.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,72 @@
'use strict';

describe('ifElse', () => {
// const { ifElse } = require('./ifElse');
const { ifElse } = require('./ifElse');

it('should ', () => {
let condition;
let first;
let second;

beforeEach(() => {
condition = jest.fn();
first = jest.fn();
second = jest.fn();
});

// write tests here
it('should be declared', () => {
expect(ifElse).toBeInstanceOf(Function);
});

it('should call first if condition returns true', () => {
condition.mockReturnValue(true);

ifElse(condition, first, second);

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

expect(first).toHaveBeenCalledTimes(1);
expect(first).toHaveBeenCalledWith();

expect(second).not.toHaveBeenCalled();
Comment on lines +28 to +31

Choose a reason for hiding this comment

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

These checks are redundant. The assertion on line 28 duplicates the one on line 25, and the assertion on line 31 duplicates the one on line 26. You can remove these repeated checks to keep your test case more concise.

});

it('should call second if condition returns false', () => {
condition.mockReturnValue(false);

ifElse(condition, first, second);

expect(condition).toHaveBeenCalledTimes(1);
expect(condition).toHaveBeenCalledWith();

expect(first).not.toHaveBeenCalled();

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

it('should call condition without arguments', () => {
condition.mockReturnValue(true);

ifElse(condition, first, second);

expect(condition).toHaveBeenCalledTimes(1);
expect(condition).toHaveBeenCalledWith();
});

it('should call callbacks without arguments', () => {
condition.mockReturnValue(false);

ifElse(condition, first, second);

expect(second).toHaveBeenCalledWith();
});

it('should not return any value', () => {
condition.mockReturnValue(true);

const result = ifElse(condition, first, second);

expect(result).toBeUndefined();
});
});