-
Notifications
You must be signed in to change notification settings - Fork 262
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
Bug: Test inner function of setup in Vue 2.7/3? #1710
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
That kind of mock is technically impossible in JS. The mock replaces the content of the |
@LinusBorg your deleted comment might actually be the case. I have to separate that inner and outer functions to a composable so I can test it like const mockInner = jest.fn()
jest.mock('./composables/use-something', () => ({
useSomething: () => ({
inner: mockInner,
outer: jest.fn()
}),
})) which works.. so If I don't want it to be a composable because it's only used in a single file... the only solution I guess is to add a methods property (Options API) and put the inner and outer functions there. Jest was able to spy if it's in the methods {
methods: {
inner() {
console.log(123)
},
outer() {
inner()
}
} |
@walmartwarlord I'm off work, so I read quickly through the issue, but I think what you want to do should work (with latest Vue 3 and VTU 2) See the unit test I added here in VTU to check that we support it: https://github.com/vuejs/test-utils/blob/main/tests/vm.spec.ts#L28-L47 If that is not the case, can you provide a repro (ideally a failing test based on this stackblitz)? |
Thanks @cexbrayat. The thing is I am using VTU 1, and I just posted the question here since VTU repo looks unmaintained. I checked the link and looks like I can just apply the implementation of Thank you! |
I added this test to fix a regression with recent versions of jest (see #310). That might not be needed in VTU v1 In any case, you should open your issue on Thanks! |
I created a basic test here @cexbrayat https://stackblitz.com/edit/vitest-dev-vitest-zmckj4 So basically I can just move those functions to a composable so I can mock it... but I have tons of components and those functions are only used in that component so I don't see moving it to a composable making sense... |
Subject of the issue
Unable to mock inner function called by a returned function
Steps to reproduce
Expected behaviour
It should have been called
Actual behaviour
The text was updated successfully, but these errors were encountered: