"async-component-wrapper-stub" testing
Hello.
A part of my component is:
And a part of my test:
console.log show
But test is not success:
How can I improve the test to get it to pass?
How can I improve the test to get it to pass?
3 Replies
Hi @Yuri. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To improve your test and make it pass, you need to consider a few things about testing async components in Vue and Nuxt. Let's break down the problem and provide a solution based on the knowledge sources:
1. The
LazySearchQuickSuggests
component is an async component, which is why it's being rendered as an <async-component-wrapper-stub>
in your shallow mount test.
2. When testing async components, you need to use mountSuspended
instead of shallowMount
to properly handle the async nature of the component.
Here's how you can improve your test:
1. Use mountSuspended
from @nuxt/test-utils/runtime
:
2. If you still encounter issues, you might need to mock the LazySearchQuickSuggests
component using mockComponent
:
3. Make sure you have the correct Vitest configuration in your vitest.config.ts
:
These changes should help your test pass by properly handling the async component and the Nuxt environment.
Sources:
Docs > Getting-started > Testing > Unit Testing > 🛠️ Helpers > mountSuspended
(https://nuxt.com/docs/getting-started/testing#mountsuspended)
Docs > Getting-started > Testing > Unit Testing > 🛠️ Helpers > mockComponent
(https://nuxt.com/docs/getting-started/testing#mockcomponent)
Docs > Getting-started > Testing > Unit Testing > Setup (https://nuxt.com/docs/getting-started/testing#setup)
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@740173469404364872> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Ups... It was the mistake in the name of the imported component.
This is correct:
SearchQuickSuggestsComponent = wrapper.findComponent(SearchQuickSuggests);
Test is pass.