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

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

it('should ', () => {
it(`shouldn't return anything`, () => {
const condition = () => true;
const first = () => true;
const second = () => true;

expect(ifElse(condition, first, second)).toBeUndefined();
});

// write tests here
it(`should call first if condition is true`, () => {
let result = 0;
const condition = () => true;
const first = () => (result = 1);
const second = () => (result = 2);

ifElse(condition, first, second);

expect(result).toBe(1);
});

it(`should call second 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 is a good test for the false condition. To make the tests more robust, consider adding another test case for when the condition returns a 'truthy' value that is not strictly true (e.g., 1 or 'hello'). This will verify that the second callback is correctly called for any value other than true, which is how the current implementation behaves.

let result = 0;
const condition = () => false;
const first = () => (result = 1);
const second = () => (result = 2);

ifElse(condition, first, second);

expect(result).toBe(2);
});
});