Skip to content
Open

task #230

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
68 changes: 65 additions & 3 deletions src/ifElse.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,73 @@
'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 call the first function when condition is true', () => {
condition.mockReturnValue(true);

ifElse(condition, first, second);

expect(first).toHaveBeenCalled();
expect(second).not.toHaveBeenCalled();
});

it('should call the second function when condition is false', () => {
condition.mockReturnValue(false);

ifElse(condition, first, second);

expect(second).toHaveBeenCalled();
expect(first).not.toHaveBeenCalled();
});

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

ifElse(condition, first, second);

expect(condition).toHaveBeenCalledTimes(1);

Choose a reason for hiding this comment

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

This assertion correctly verifies that condition is called. However, the requirements also state that it should be called with no arguments. You should add another assertion here to verify that, for example: expect(condition).toHaveBeenCalledWith();.

});

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

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

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

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

ifElse(condition, first, second);

expect(first).toHaveBeenCalledWith();
});

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

ifElse(condition, first, second);

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

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

ifElse(condition, first, second);

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