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
28 changes: 25 additions & 3 deletions src/ifElse.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
'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 function', () => {
expect(typeof ifElse).toBe('function');
});

it(`should call 'first' if 'condition' returns true`, () => {
condition.mockReturnValue(true);
ifElse(condition, first, second);
expect(first).toHaveBeenCalled();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This correctly verifies that the first callback is executed. The requirements also state that callbacks should be run 'with no arguments'. To make this test more precise, you could also check that both condition and first were called without any arguments using toHaveBeenCalledWith().

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

it(`should call 'second' if 'condition' returns false`, () => {
condition.mockReturnValue(false);
ifElse(condition, first, second);
expect(first).not.toHaveBeenCalled();
expect(second).toHaveBeenCalled();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This check is correct. To fully align with the requirements, consider also asserting that both the condition and second callbacks were called without arguments.

});
});