-
Notifications
You must be signed in to change notification settings - Fork 253
Add solution #244
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 solution #244
Changes from 2 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,37 @@ | ||
| 'use strict'; | ||
|
|
||
| describe('ifElse', () => { | ||
| // const { ifElse } = require('./ifElse'); | ||
|
|
||
| it('should ', () => { | ||
| const { ifElse } = require('./ifElse'); | ||
|
|
||
| it('should return undefined', () => { | ||
| expect( | ||
| ifElse( | ||
| () => Math.random() > 0.5, | ||
| () => {}, | ||
| () => {}, | ||
| ), | ||
| ).toBeUndefined(); | ||
| }); | ||
|
|
||
| // write tests here | ||
|
|
||
| it('should call first callback if condition is true', () => { | ||
| const condition = jest.fn(() => true); | ||
| const first = jest.fn(); | ||
| const second = jest.fn(); | ||
|
|
||
| ifElse(condition, first, second); | ||
| expect(first).toHaveBeenCalledWith(); | ||
| expect(second).not.toHaveBeenCalledWith(); | ||
|
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. This is a good check. To be even more precise, you can use
|
||
| }); | ||
|
|
||
| it('should call second callback if condition is false', () => { | ||
| const condition = jest.fn(() => false); | ||
| const first = jest.fn(); | ||
| const second = jest.fn(); | ||
|
|
||
| ifElse(condition, first, second); | ||
| expect(first).not.toHaveBeenCalledWith(); | ||
|
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. Similar to my other comment, using |
||
| expect(second).toHaveBeenCalledWith(); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great improvement! To fully meet the requirements, you also need to verify that the
conditioncallback is called with no arguments. Please add an expectation to check this here and in the test case below.