Using .mock() as a .default() only in testing?
See original GitHub issueHey hey,
So we are looking at using a “zod first approach” to developing libraries (DDD?).
As such we have just been looking at a way to quickly mock inputs during develop and testing. One idea we had was to use .default() to produce the test data - but then we realised this didn’t make sense as we would then have these defaults in production as well.
It would be great if there were an equivalent .mock()
that would return a mock value if no other is received and node env == dev
or test
(or some other config).
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
How to test default argument called by a mocked method?
Just call it and use : self.assertEqual(sendContent(), "SOME_PATH"). Share.
Read more >A Unit Testing Practitioner's Guide to Everyday Mockito - Toptal
By default, all methods of a mock return “uninitialized” or “empty” values, e.g., zeros for numeric types (both primitive and boxed), false for...
Read more >unittest.mock — mock object library — Python 3.11.1 ...
If the function returns DEFAULT then the mock will return its normal value (from the return_value ).
Read more >Clean Unit Tests with Mockito - Reflectoring
In this article we will learn how to mock objects with Mockito. We'll first talk about what test doubles are and then how...
Read more >Mock Functions - Jest
You can optionally provide a name for your mock functions, which will be displayed instead of 'jest.fn()' in the test error output. Use...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The ability to passing a “dynamic default” function into
.default
is now available in zod@2.0.0-beta.16 👍Zod makes sure the returned value matches the expected type signature:
I just opened an RFC for mocking here: https://github.com/vriad/zod/issues/197
Feel free to comment 🤙