question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when mounting a single component

See original GitHub issue

Hello 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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
cexbrayatcommented, Nov 23, 2020

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:

const AsyncWrapper = defineComponent({
  components: { AsyncSetup },
  template: `<Suspense><AsyncSetup/></Suspense>`
});

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?

0reactions
cexbrayatcommented, Nov 23, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found