Error when mounting a single component
See original GitHub issueHello there,
when mounting a single component, as done previously using the vue2 setup, I now get the following exception logged when trying to call the html() method on the wrapper:
TypeError: Cannot read property ‘parentElement’ of null
The behaviour is equivalent for the text() method.
When I am mounting my whole app, and not just the component, the issue is gone.
Could you explain if this is desired behaviour and how to test a component in isolation now?
my component:
<template>
<div>
<span>Pls render me..</span>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
name: 'AsyncSetup',
async setup() {
return {};
},
});
</script>
<style lang="scss" scoped></style>
and a simple test case:
describe('AsyncSetup.vue', () => {
it('should text as expected', async () => {
const wrapper = mount(AsyncSetup);
await nextTick();
await flushPromises();
expect(wrapper.html()).toMatchSnapshot(); // exception happens here, during the hmtl() call
});
});
Thanks & Best Regards
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
ReactJS - setState error when unMounting and Mounting
This is a error that I get when I unmounted and then mounted component: Warning: setState(...): Can only update a mounted or mounting...
Read more >An error occurred mounting one of your file systems WSL error
This error appears when one tries to install WSL or tries to open it. The problem in both cases is that your WSL...
Read more >【Help Wanted】Failed to mount Vue component error #4644
I've managed to make it work without typescript. Thise error: [Vue warn]: Failed to mount component: template or render function not defined.
Read more >Failed to mount component error - Get Help - Vue Forum
Hey everyone. I started running into this error when I added an import to a . vue file.
Read more >“Unable to install. A required install component is missing or ...
Unable to install A required install component is missing or corrupted. Error 3051" appears when attempting to install an Autodesk update.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ha yes OK, I understand now.
If your component has an async setup, you probably need to mount it in a “fake” async wrapper that has a
Suspense
(like you do in your real application I guess).Something like:
And then
mount(AsyncWrapper)
I agree that this is a bit tricky, and we were thinking of providing a
mountAsync
function, that would basically do that. Does that help?Happy to hear your test works.
We are definitely waiting for Suspense to stabilize a bit before making a decision, so we are all currently doing the same thing. Maybe we’ll add a built-in function or add it in a plugin, we’ll see.