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

Add more documentation on auto-mocking #6812

Closed
Morikko opened this issue Aug 7, 2018 · 6 comments · Fixed by #8099
Closed

Add more documentation on auto-mocking #6812

Morikko opened this issue Aug 7, 2018 · 6 comments · Fixed by #8099

Comments

@Morikko
Copy link

Morikko commented Aug 7, 2018

🚀 Feature Proposal

Add more documentation on what auto-mocking do, especially for jest.genMockFromModule.
The purpose is to say how each type is transformed by Jest.

Motivation

You have to test the mocked object to know how each type is transformed by jest.

Example

  • Function -> Create a mock function that returns undefined
  • Async Function -> Create a mock function (synchronous) that returns undefined
  • Object -> Do a deep copy of the object (keep the interface) and mock the sub elements
  • Class -> Keep the interface and the type but all the functions are mocked
  • Array -> Empty array
  • String -> copy
  • Number -> copy
  • Date -> undefined

I could do the PR, however I would gladly appreciate a review of those assumptions.
Also, if some types are missing, let me know.

@SimenB
Copy link
Member

SimenB commented Sep 16, 2018

@Morikko sorry about the slow response. Yeah, as far as I know, those assumptions holds true. The logic lives here: https://github.com/facebook/jest/blob/68eb9a232dcbd4ecf85bb1f0bdad5cb850dff81a/packages/jest-mock/src/index.js#L646-L723

A PR adding a test verifying those assertions in addition to the docs would be greatly appreciated 🙂

@mackness
Copy link
Contributor

mackness commented Mar 7, 2019

Hi @Morikko and @SimenB if you guys think this still needs to be worked on I would not mind picking it up.

@jeysal
Copy link
Contributor

jeysal commented Mar 7, 2019

@mackness the documentation on this is still not very detailed, so I think some improvements would be great :)

@Morikko
Copy link
Author

Morikko commented Mar 8, 2019 via email

@mackness
Copy link
Contributor

I created a PR and I think I'm on the right track but any feedback is greatly appreciated. Definitely open to making improvements. Thanks!

#8099

@github-actions
Copy link

This issue 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 May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants