-
Notifications
You must be signed in to change notification settings - Fork 56
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
Handle primitive values #4
Comments
I'll take a look at this, but suspect that it will not work as you have specified there given how jest works and how I've implemented deep mocks. It may require something like : mock<Foo>({
baz: {
quux: primitiveMock().mockReturnValueOnce(false)
}
) or const foo = mock<Foo>()
// modifidy mock return value for quux
primitiveMock(foo.baz.quux).mockReturnValueOnce(false) |
Is there any update on this? It would really be useful to the current project I'm testing. |
unfortunately since Jest does not support this, the only way to add this is to do as above. PRs welcome |
My current workaround is this:
If you do not need spying capabilities and just want
But this seems to be more complicated then necessary. It should be possible to write
And actually, this does work (even with mockDeep), but not for falsy values like in the example. I believe this is due to line 86 in Mock.ts, which reads |
I tested this solution and it works great. Why is this fix not committed yet? |
I see some benefit to being able for
mock<...>()
to also mock primitive values.For example:
Refer to #3 and https://github.com/reergymerej/super-mockable-non-functions/blob/master/src/index.js
Thoughts?
The text was updated successfully, but these errors were encountered: