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

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

it('should ', () => {});
it('should call first if condition is true', () => {
const condition = () => true;

// write tests here
const first = jest.fn();
const second = jest.fn();

ifElse(condition, first, second);

expect(first).toHaveBeenCalled();
expect(second).not.toHaveBeenCalled();
Comment on lines +14 to +15
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These assertions are correct, but they could be more specific. The task description mentions that condition should be called with no arguments (and it's implied for first as well).

To fully test this, you could also:

  1. Make condition a jest.fn() to check if it has been called.
  2. Use toHaveBeenCalledWith() to verify that both condition and first are called with no arguments.

});

it('should call second if condition is false', () => {
const condition = () => false;

const first = jest.fn();
const second = jest.fn();

ifElse(condition, first, second);

expect(second).toHaveBeenCalled();
expect(first).not.toHaveBeenCalled();
Comment on lines +26 to +27
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Similar to the previous test, you can make these assertions more precise. The requirements explicitly state that condition and second should be called with no arguments.

Consider making condition a mock function and using toHaveBeenCalledWith() for both condition and second to ensure they are called correctly.

});

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

const first = jest.fn();
const second = jest.fn();

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

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