Skip to content

Bug: Spy a function in a function if these 2 functions have been declared in the same vue component #1799

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

Closed
mattaiod opened this issue Oct 6, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@mattaiod
Copy link

mattaiod commented Oct 6, 2022

Describe the bug
Spying a function in a function in a Vue component if these 2 functions are declared in the same vue file doesn't work.

To Reproduce
Minimum reproduction:
https://github.com/mattaiod/VITEST-cant-spy-fn-in-fn-in-component

Expected behavior
Since I have spied fnInside, when I call fnOutside, fnInside should be called

Related information:

@vue/test-utils: 2.1.0
vitest: 0.23.4
Vue: 3.2.40
node: v16.13.1
pnpm: 7.8.0

@mattaiod mattaiod added the bug Something isn't working label Oct 6, 2022
@cexbrayat
Copy link
Member

@mattaiod I answered in #1798 and I don't think you changed something since then?

Is there anything else we can do to help?

Duplicates #1798

@cexbrayat cexbrayat closed this as not planned Won't fix, can't repro, duplicate, stale Oct 6, 2022
@mattaiod
Copy link
Author

mattaiod commented Oct 6, 2022

@cexbrayat Hi, No it's not a duplication.

In my last issue, it was about mocking a function in a function whereas in this current issue it's about spying a function in a function and know if the inner function was called.

I can imagine the problem is similar though...

@cexbrayat
Copy link
Member

@mattaiod Yes, it's exactly the same issue.

@freakzlike
Copy link
Collaborator

Spying and mocking is using the same technique by replacing the original function. But this only works for functions which are part of an object and accessible from outside. That's not vue specific and the same thing for common js modules as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants