I'm writing unit tests for my Vue 3 Composition API component in Vitest. All of my unit tests pass for the component without an issue - however, I'm getting this warning from Vue when I run them:
[Vue warn]: Non-function value encountered for default slot. Prefer function slots for better performance.
The offending code is a Teleport
tag that renders a modal when a store value is true. If I comment that code out, or empty the slot of any content, the warning does not appear. I have tried stubbing Teleport
, where the template is <div>Hello World</div>
and <div><slot></slot></div>
, but this did not resolve the issue.
<Teleport to="body">
<Modal v-if="showModal" :is-open="showModal" @close="closeModal">
<component
:is="childBlock.component"
v-for="childBlock in $store.ui.getActiveModalCardContent"
:key="childBlock._uid"
:blok="childBlock"
class="col-span-2"
/>
</Modal>
</Teleport>
I've looked up the warning code but the solutions I've seen use a render function to create their components rather than it happening with a template. I don't get any issues, warnings or otherwise, in the console when the app runs; only when testing.
I've tried swapping out some of the data being passed in with a function that returns the data instead and this didn't work.
Am I missing some kind of manual import? Or do I need to vi.mock()
something?
These are the most relevant solutions I could find but tried applying the solutions without success:"Non-function value encountered for default slot." in Vue 3 Composition API component