-
Notifications
You must be signed in to change notification settings - Fork 255
Add task solution #237
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 #237
Changes from 1 commit
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,47 @@ | ||
| 'use strict'; | ||
|
|
||
| const { ifElse } = require('./ifElse'); | ||
|
|
||
| describe('ifElse', () => { | ||
| // const { ifElse } = require('./ifElse'); | ||
| it('calls the condition callback once', () => { | ||
| const condition = jest.fn(() => true); | ||
| const first = jest.fn(); | ||
| const second = jest.fn(); | ||
|
|
||
| ifElse(condition, first, second); | ||
|
|
||
| expect(condition).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('runs the first callback when condition returns true', () => { | ||
| const condition = jest.fn(() => true); | ||
| const first = jest.fn(); | ||
| const second = jest.fn(); | ||
|
|
||
| ifElse(condition, first, second); | ||
|
|
||
| it('should ', () => { | ||
| expect(first).toHaveBeenCalledTimes(1); | ||
|
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. Good job checking that the |
||
| expect(second).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('runs the second callback when condition returns false', () => { | ||
| const condition = jest.fn(() => false); | ||
| const first = jest.fn(); | ||
| const second = jest.fn(); | ||
|
|
||
| ifElse(condition, first, second); | ||
|
|
||
| expect(second).toHaveBeenCalledTimes(1); | ||
|
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 correctly tests that the |
||
| expect(first).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| // write tests here | ||
| it('returns undefined', () => { | ||
| const condition = jest.fn(() => true); | ||
| const first = jest.fn(); | ||
| const second = jest.fn(); | ||
|
|
||
| const result = ifElse(condition, first, second); | ||
|
|
||
| expect(result).toBeUndefined(); | ||
| }); | ||
| }); | ||
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 assertion correctly verifies that
conditionis called. The requirements also state that it should be run with no arguments. You can strengthen this test by also asserting it was called with no arguments, for example, by using.toHaveBeenCalledWith().