-
Notifications
You must be signed in to change notification settings - Fork 668
shallowMount() behaves like mount() when components are lazy loaded #1279
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
Comments
Duplicate of #959 |
Hi there, I was wondering if there's any update on this.. We have the exact same issue. |
As I see in your Github you are using the Jest, lazy load (() => import) and of course NodeJS. "Jest runs in Node, and thus requires ES modules to be transpiled to CommonJS modules. Solution: // my .babelrc
// my jest.config.js
// my env:
"vue": "^2.5.17", "babel-core": "^6.26.3", "laravel-mix": 4.0.7,
|
I face a similar issue when using to dynamic components as the components that are set get fully rendered. Would a fix for this issue cover this use case as well? |
I've added your solution to the reproduction package ( https://github.com/xavism/lazyloading-vue-test-utils) and it is still not working. |
have you found a solution for that? |
Unfortunately no :( |
still no update on this? |
So I think the reason this happens is because the way If my guess is correct, this is not something we can fix without a major rework of the library. The only suggested I can come up with to make your snapshots match is to use If anyone wants to dig into this one, I can provide some guidance or even pair with you on it. |
As a less-than-ideal workaround, you can explicitly provide stubs for async components. |
I am having the same issue, I lazy load my components, and shallowMount behave like mount, but mount itself doesn't really work. I created a factory function to switch easily between mount and shallow, but mount just doesn't work. |
Call me crazy but if you are loading a component why would you want to use |
Hi @lmiller1990 , first of all thanks for your time. |
I see, makes sense. Time for a deep dive into the dark depths of |
Since For example,
Step 1. Change
Step 2. Add
The child component will be mount as |
^ seems like a good work around! |
@lmiller1990 I wonder that if |
I have no idea why this happens, I took a look but didn't have much luck fixing it. I would probably need to spend more time on it. If you would like to try figuring it out I can try to help out. I personally recommend against using |
I have tried hacking this as well many times, alas got nowhere... I think this is finally fixed in VTU 2 though 😄 |
@dobromir-hristov Do we have a confirmation that it's actually fixed in Vue Test Utils 2 / Vue 3? |
I just cloned and updated the repo linked in the first post. I used Vue 3, VTU v2 and ts-jest v25. The first two tests passed fine, I had to update the snapshots with So yep, seems fine. This is because the shallow mounting is (kind of) baked into Vue core now via a Of course that is in a different codebase using different dependencies - I do not expect this issue will be fixed in VTU v1 (for Vue 2) at this point. |
@lmiller1990 Should I mark this ticket as |
Considering how much time has passed and how complex this likely is to fix, I'd say closed and wontfix is probably fine -- it's clear there isn't a lot of motivation to fix this particular issue. |
I just wanted to mention that we had this issue before and it simply went away after upgrading from Vue 2.5 to 2.7. We're on Jest v29. |
Version
1.0.0-beta.29
Reproduction link
https://github.com/xavism/lazyloading-vue-test-utils
Steps to reproduce
$ npm i
$ npm t
Then check the snapshots
What is expected?
Both snapshots (Parent and ParentLazy) are expected to be the same. shallowMount should stub the child components
What is actually happening?
ParentLazy's snapshot is rendering the Child component when using shallowMount, the child component in the snapshot is not stubbed
Related to a closed issue:
shallowMount will not stubs lazily registered components #959
#959
It should be fixed but it's not working in my case.
The text was updated successfully, but these errors were encountered: