Skip to content
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

Correcting mockClear api docs #12019

Merged
merged 7 commits into from
Nov 2, 2021
Merged

Correcting mockClear api docs #12019

merged 7 commits into from
Nov 2, 2021

Conversation

Biki-das
Copy link
Contributor

@Biki-das Biki-das commented Nov 1, 2021

Documentation page:
https://jestjs.io/docs/mock-function-api#mockfnmockclear

Summary

mock.mockClear() and clearMocks:true are reseting ``mock.calls,mock.instances and `mock.results` of a mock function not only the first two ones that doc say


module.exports = {
   clearMocks: false,
   resetMocks: false
}```

```const mock = jest.fn(x => x * 2);

beforeEach(() => {
   mock.mockClear()
})

it('test1', () => {
   mock(2);
   mock(3);
   console.log(mock.mock.calls, mock.mock.instances, mock.mock.results);
   // [ [ 2 ], [ 3 ] ]
   // [ undefined, undefined ]
   // [ { type: 'return', value: 4 }, { type: 'return', value: 6 } ]
});

it('test2', () => {
   console.log(mock.mock.calls, mock.mock.instances, mock.mock.results);
   // [] [] []
});

Removing beforeEach() and toggling clearMocks config option won't affect the result

@Biki-das
Copy link
Contributor Author

Biki-das commented Nov 1, 2021

@SimenB please review

@mrazauskas
Copy link
Contributor

@Biki-das It makes sense.

Could you add mock.results to the documentation of jest.clearAllMocks() as well – https://jestjs.io/docs/jest-object#jestclearallmocks

@Biki-das
Copy link
Contributor Author

Biki-das commented Nov 2, 2021

@Biki-das It makes sense.

Could you add mock.results to the documentation of jest.clearAllMocks() as well – https://jestjs.io/docs/jest-object#jestclearallmocks

i am kinds confused where should i add it

@mrazauskas
Copy link
Contributor

Oh, sorry.

Right now it states: "Clears the mock.calls and mock.instances properties of all mocks."
Seems like it should be: "Clears the mock.calls, mock.instances and mock.results properties of all mocks."

Or I mixed up something?

@codecov-commenter
Copy link

codecov-commenter commented Nov 2, 2021

Codecov Report

Merging #12019 (3882238) into main (10d9580) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #12019   +/-   ##
=======================================
  Coverage   68.77%   68.77%           
=======================================
  Files         324      324           
  Lines       16669    16669           
  Branches     4813     4813           
=======================================
  Hits        11464    11464           
  Misses       5172     5172           
  Partials       33       33           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 10d9580...3882238. Read the comment docs.

@Biki-das
Copy link
Contributor Author

Biki-das commented Nov 2, 2021

/review @SimenB

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@SimenB
Copy link
Member

SimenB commented Nov 2, 2021

Prettier is unhappy, could you run yarn lint:prettier locally?

@Biki-das
Copy link
Contributor Author

Biki-das commented Nov 2, 2021

Prettier is unhappy, could you run yarn lint:prettier locally?

sure

@Biki-das
Copy link
Contributor Author

Biki-das commented Nov 2, 2021

@SimenB i want to thank you , you are really a nice person to work with,😊😊

docs/JestObjectAPI.md Outdated Show resolved Hide resolved
@Biki-das
Copy link
Contributor Author

Biki-das commented Nov 2, 2021

@SimenB sorry for the issue! Hope it's fine now

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect, thanks again!

@github-actions
Copy link

github-actions bot commented Dec 3, 2021

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants