-
Notifications
You must be signed in to change notification settings - Fork 352
solution #324
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 #324
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,31 @@ | ||
| 'use strict'; | ||
| "use strict"; | ||
|
|
||
| describe('restoreNames', () => { | ||
| // const { restoreNames } = require('./restoreNames'); | ||
| describe("restoreNames", () => { | ||
| const { restoreNames } = require("./restoreNames"); | ||
|
|
||
| it('should ', () => { | ||
| const users = [ | ||
| { | ||
| firstName: undefined, | ||
| lastName: "Holy", | ||
| fullName: "Jack Holy", | ||
| }, | ||
| { | ||
| lastName: "Adams", | ||
| fullName: "Mike Adams", | ||
| }, | ||
| ]; | ||
|
||
|
|
||
| it("should be a function", () => { | ||
| expect(restoreNames).toBeInstanceOf(Function); | ||
| }); | ||
|
|
||
| // write tests here | ||
| it("should have firstName", () => { | ||
|
||
| restoreNames(users); | ||
| expect(users[0].firstName).toBe("Jack"); | ||
| }); | ||
|
|
||
| it("should have firstName", () => { | ||
| restoreNames(users); | ||
| expect(users[1].firstName).toBe("Mike"); | ||
| }); | ||
| }); | ||
|
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. One of the key requirements is that the function should not return a value. As mentioned in the previous review, you need to add a test case to verify that calling |
||
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
usersarray is defined in a shared scope and gets mutated by your first test. The second test then operates on this already-modified data, which means it isn't testing the original scenario. Tests must be independent. To fix this, you can either create a fresh copy of theusersarray inside eachitblock or use Jest'sbeforeEachhook to reset the data before each test.