-
Notifications
You must be signed in to change notification settings - Fork 264
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
Stub does not work for async component #514
Comments
I found out that it is required to set a name in the async component and use this name in import { flushPromises, mount } from '@vue/test-utils'
import { defineAsyncComponent, defineComponent } from '@vue/runtime-core'
it('should stub async component', async () => {
const AsyncComponent = defineComponent({
name: 'AsyncComponent',
template: '<span>AsyncComponent</span>'
})
const StubComponent = defineComponent({
template: '<span>StubComponent</span>'
})
const TestComponent = defineComponent({
template: '<MyComponent/>',
components: {
MyComponent: defineAsyncComponent(async () => AsyncComponent)
}
})
const wrapper = mount(TestComponent, {
global: {
stubs: {
AsyncComponent: StubComponent
}
}
})
await flushPromises()
expect(wrapper.html()).toContain('StubComponent')
}) I have created an pull request which adds a section to the docs for stubbing an async component. See #516 |
Hi! Thank you for the reproduction and the effort to open up a PR ❤️ I feel this could be handled by VTU internals, instead of asking users to add a name to a component? 🤔 |
@afontcu You are right. I will have a look at it |
I created a PR to handle async components the same way as "sync" components. See #518 |
When trying to stub an async component it still renders to original component instead of the stub component.
Version: 2.0.0-rc.4
Expected HTML to be
<span>StubComponent</span>
instead of<span>AsyncComponent</span>
.The text was updated successfully, but these errors were encountered: