From fcc6edec121cc1ccaec69084d40857af1f7c4e6c Mon Sep 17 00:00:00 2001 From: Aliona Date: Thu, 11 Dec 2025 00:49:16 +0200 Subject: [PATCH 1/2] task --- src/ifElse.test.js | 60 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/src/ifElse.test.js b/src/ifElse.test.js index 95985e0..6e87b1b 100644 --- a/src/ifElse.test.js +++ b/src/ifElse.test.js @@ -1,11 +1,65 @@ '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 secont 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); + }); + + 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(); + }); }); From a9ce0b875bb41d87700e92f49fba7136e6723410 Mon Sep 17 00:00:00 2001 From: Aliona Date: Thu, 11 Dec 2025 00:54:21 +0200 Subject: [PATCH 2/2] fix --- src/ifElse.test.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ifElse.test.js b/src/ifElse.test.js index 6e87b1b..ea3eeef 100644 --- a/src/ifElse.test.js +++ b/src/ifElse.test.js @@ -22,7 +22,7 @@ describe('ifElse', () => { expect(second).not.toHaveBeenCalled(); }); - it('should call the secont function when condition is false', () => { + it('should call the second function when condition is false', () => { condition.mockReturnValue(false); ifElse(condition, first, second); @@ -62,4 +62,12 @@ describe('ifElse', () => { expect(second).toHaveBeenCalledWith(); }); + + it('should call condition without arguments', () => { + condition.mockReturnValue(true); + + ifElse(condition, first, second); + + expect(condition).toHaveBeenCalledWith(); + }); });