Document how to mock a class, an instance, a method in a class
weedySeaDragon opened this issue · comments
Clear and concise description of the problem
The documentation explains how to mock modules, functions, etc., but never explains how to mock classes and their related entities. There are many approaches out on the web; a developer has to wade through different approaches and test each of them to determine if they are correct or not.
Suggested solution
The documentation should have verified explanations and examples for mocking:
- an entire class
- an instance of a class
- a single method from a class
- other related entities that should also be included
This will likely mean some extended discussions in order to agree on correct approaches. (And perhaps only one of many valid approaches is shown, with pointers or a brief explanation for others.)
Discussion(s) could take place in.... the discussions .
Related: #4001 Utility to auto mock class instance
I'm quite interested in this and can will kick-off a discussion.
Alternative
No response
Additional context
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Doesn't "Mock exported class implementation" on the same page you listed already cover it?
I'm proposing that the documentation be updated to include examples of how to mock not just an instance of a class, but a single method, or a static method, or all instances of a class, etc., to cover all of the OO/class things can be mocked.
(And sorry for the delay in responding. I appreciate that you responded quickly. :-) )