-
Notifications
You must be signed in to change notification settings - Fork 668
Component stubs stop working for grand children when registered globally #830
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
I think the reason this is happening is because at the moment Edit: rolling back to One work around is to use expect(wrapper.find(GrandChildComponent).exists()).toBe(true) Or you simply pass an object with a expect(wrapper.find({ name: "grand-child-component" }).exists()).toBe(true); Maybe related to #649 - a 'dive' or My personal experience is using |
This is a bug, stubs should be applied to all child components |
This actually is a problem with how you're stubbing. First you were using Vue Test Utils beta.16 which would stop circular references, because the class had the name of the component it would throw an error (this has been fixed to only throw if the component name is the same). Second, you were trying to find the element using a -stub suffix on the class, which is not added when it's stubbed. Third, the TestComponent wasn't rendering the ChildComponent. I've added these fixes to your code sample: https://codesandbox.io/s/jpo3lo2569. There's a passing test for stubbing nested components in the Vue Test Utils—https://github.com/vuejs/vue-test-utils/blob/dev/test/specs/mounting-options/stubs.spec.js#L135 |
@eddyerburgh In the first test you can see that the child component stub is applied ( In the second test you can see that the grand child component stub is not applied. The generated html still shows a div with the text "I am the grand child". If the stub would be applied then it should be replaced by a Clarification on that would be appreciated :) |
Sorry, yes this is in fact a bug. |
This is fixed in master, and will be included in the next release. For now, a quick solution is to use localVue: import { createLocalVue } from '@vue/test-utls'
const localVue = createLocalVue()
localVue.component('child-component', Child)
mount(TestComponent, {
localVue
}) |
Hello, |
@Igor-Dataka and anyone else that ran into this problem and got taken to this GitHub issue via search engines: It doesn't seem that vue-test-utils supports a situation where the child component contains a dynamic import { describe, expect, jest, it } from '@jest/globals';
import { createLocalVue, mount, RouterLinkStub } from '@vue/test-utils';
import MyComponent from './MyComponent';
describe('MyComponent component', () => {
it('renders with default props', () => {
const localVue = createLocalVue();
localVue.component('router-link', RouterLinkStub);
const wrapper = mount(MyComponent, {
localVue
});
expect(true);
}); |
Yeah, I don't think this is supported. Stubs are applied before the runtime, so I suspect that's the reason - the stubs are applied before the dynamic behavior. I have found that writing unit tests around routing logic is generally brittle and generates more work/maintenance then value, I generally recommend against unit testing that sort of thing. |
Version
1.0.0-beta.20
Reproduction link
https://codesandbox.io/s/7krlyqn310
Steps to reproduce
TestComponent.spec.js
What is expected?
The test for the grand child should pass as it was stubbed.
What is actually happening?
The test fails because the stub does not apply.
This only seems to be an issue with components that are registered globally. The error did not occur when the sub-componentes were registered locally.
We experienced this bug when we upgraded from beta.16 to beta.20. The transition component which is stubbed per default suddenly stopped working in nested components.
The text was updated successfully, but these errors were encountered: