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

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

it('should ', () => {
test('calls condition callback', () => {
const condition = jest.fn(() => true);
const first = jest.fn();
const second = jest.fn();

});
ifElse(condition, first, second);

// write tests here
expect(condition).toHaveBeenCalledWith();
});

test('calls first callback when condition returns true', () => {
const condition = jest.fn(() => true);
const first = jest.fn();
const second = jest.fn();

ifElse(condition, first, second);

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

test('calls second callback when condition returns false', () => {
Comment thread
gmarchese93 marked this conversation as resolved.
const condition = jest.fn(() => false);
const first = jest.fn();
const second = jest.fn();

ifElse(condition, first, second);

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

test('calls second callback when condition returns a truthy value other than true', () => {

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

View workflow job for this annotation

GitHub Actions / build (12.x)

Line 37 exceeds the maximum line length of 80
const condition = jest.fn(() => 1); // truthy but not true
const first = jest.fn();
const second = jest.fn();

ifElse(condition, first, second);

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

test('returns nothing', () => {
const condition = jest.fn(() => false);
const first = jest.fn();
const second = jest.fn();

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

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