-
Notifications
You must be signed in to change notification settings - Fork 254
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
Jest is no longer able to spy on methods #309
Comments
Hi there! Thank you for opening an issue. That's weird, I have similar code in all my apps, and it does work well for me 🤔 Can you provide us a small reproduction so we can investigate? |
Sure! setup (props) {
const { send, state } = useMachine(assetsMachine)
const doThing = () => {
send('hello')
}
return {
send,
doThing,
} However, trying to spy on send yields that error, even though |
Can you push your repro on a Githup repo please? We'll need to know how your project is set up. Ideally just a small component like this one, and a failing unit test with the error 👍 |
I'll try to create a codesandbox, it would take hours extracting this from my project. |
That's not going to work. CodeSandbox can't even run Jest at the moment. The issue seems to be that wrapper.vm is a Proxy object and jest.spyOn can't find the method on wrapper.vm as it doesn't have a |
I managed to repro your issue, but I don't have an obvious fix right now. This may need some thinking. |
Thanks a ton, it's driving me up the wall haha! |
This allows Jest to spy on the proxied vm Fixes #309
We're having the same issue. Is there a time plan when this fix will be released? |
I have a fix but it's blocked by a change we need in Vue itself (vuejs/core#3105). |
I think the wrapper no longer exposes methods on the prototype or something, because when I want to spy on a method (e.g.
wrapper.vm.send
) withjest.spyOn(wrapper.vm, 'send')
Jest throws a type error:TypeError: object.hasOwnProperty is not a function
.This makes it impossible to test some component internals (like methods that format data and send it off to a state machine, in this case).
The text was updated successfully, but these errors were encountered: