-
Notifications
You must be signed in to change notification settings - Fork 253
add task solution #234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
add task solution #234
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,96 @@ | ||
| 'use strict'; | ||
| /* eslint-disable max-len */ | ||
|
|
||
| describe('ifElse', () => { | ||
| // const { ifElse } = require('./ifElse'); | ||
| const { ifElse } = require('./ifElse'); | ||
|
|
||
| it('should ', () => { | ||
| it('should be declared', () => { | ||
| expect(ifElse).toBeInstanceOf(Function); | ||
| }); | ||
|
|
||
| it('should call the condition function exactly 1 time', () => { | ||
| const condition = jest.fn(); | ||
| const first = jest.fn(); | ||
| const second = jest.fn(); | ||
|
|
||
| ifElse(condition, first, second); | ||
|
|
||
| expect(condition).toHaveBeenCalled(); | ||
| expect(condition).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('should call the first function exactly 1 time when condition returns true', () => { | ||
| const condition = jest.fn(() => true); | ||
| const first = jest.fn(); | ||
| const second = jest.fn(); | ||
|
|
||
| ifElse(condition, first, second); | ||
|
|
||
| expect(first).toHaveBeenCalled(); | ||
| expect(first).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| // write tests here | ||
| it('should not call second function when condition returns true', () => { | ||
| const condition = jest.fn(() => true); | ||
| const first = jest.fn(); | ||
| const second = jest.fn(); | ||
|
|
||
| ifElse(condition, first, second); | ||
|
|
||
| expect(first).toHaveBeenCalled(); | ||
| expect(first).toHaveBeenCalledTimes(1); | ||
| expect(second).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should call the second function exactly 1 time when condition returns false', () => { | ||
| const condition = jest.fn(() => false); | ||
| const first = jest.fn(); | ||
| const second = jest.fn(); | ||
|
|
||
| ifElse(condition, first, second); | ||
|
|
||
| expect(second).toHaveBeenCalled(); | ||
| expect(second).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('should not call first function when condition returns false', () => { | ||
| const condition = jest.fn(() => false); | ||
| const first = jest.fn(); | ||
| const second = jest.fn(); | ||
|
|
||
| ifElse(condition, first, second); | ||
|
|
||
| expect(second).toHaveBeenCalled(); | ||
| expect(second).toHaveBeenCalledTimes(1); | ||
| expect(first).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should not return anything', () => { | ||
| const condition = jest.fn(() => false); | ||
| const first = jest.fn(); | ||
| const second = jest.fn(); | ||
|
|
||
| expect(ifElse(condition, first, second)).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should call all the callbacks with no arguments', () => { | ||
| const condition1 = jest.fn(() => false); | ||
| const condition2 = jest.fn(() => true); | ||
| const first = jest.fn(); | ||
| const second = jest.fn(); | ||
|
|
||
| expect(ifElse(condition1, first, second)).toBeUndefined(); | ||
|
|
||
| expect(condition1).toHaveBeenCalledTimes(1); | ||
| expect(condition1).toHaveBeenCalledWith(); | ||
| expect(second).toHaveBeenCalledTimes(1); | ||
| expect(second).toHaveBeenCalledWith(); | ||
|
|
||
| expect(ifElse(condition2, first, second)).toBeUndefined(); | ||
|
|
||
| expect(condition2).toHaveBeenCalledTimes(1); | ||
| expect(condition2).toHaveBeenCalledWith(); | ||
| expect(first).toHaveBeenCalledTimes(1); | ||
| expect(first).toHaveBeenCalledWith(); | ||
| }); | ||
|
Comment on lines
+76
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great job adding the checks to ensure callbacks are called with no arguments! You've correctly addressed the main point from the previous review. However, this single test case is doing too much by testing both the A better approach would be to integrate these
|
||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.