-
Notifications
You must be signed in to change notification settings - Fork 256
Solution #249
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?
Solution #249
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,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(); | ||
| }); | ||
|
|
||
| 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
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 the previous test, you can make these assertions more precise. The requirements explicitly state that Consider making |
||
| }); | ||
|
|
||
| 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(); | ||
| }); | ||
| }); | ||
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.
These assertions are correct, but they could be more specific. The task description mentions that
conditionshould be called with no arguments (and it's implied forfirstas well).To fully test this, you could also:
conditionajest.fn()to check if it has been called.toHaveBeenCalledWith()to verify that bothconditionandfirstare called with no arguments.