Skip to content

Cannot mount component with async setup #1207

@ol1s

Description

@ol1s

I have the following example component and test:

const ExampleComponent = {
  template: `<div></div>`,
  async setup() {
    return {
      example: await Promise.resolve("Test"),
    }
  },
}
test("mounts example component with async setup", () => {
  const wrapper = mount(ExampleComponent)
  expect(wrapper).toBeTruthy()
})

However when I try and run the test I get the following error:

TypeError: Cannot read properties of null (reading 'addEventListener')
at _loop_1 (node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:7543:21)
at VueWrapper.Object.<anonymous>.VueWrapper.attachNativeEventListener (node_modules/@vue/test-utils/dist/vue-test utils.cjs.js:7553:13)
at new VueWrapper (node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:7504:15)
at createWrapper (node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:7682:12)
at mount (node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:7929:19)
at Object.<anonymous>

When I remove the async and promise and instead use a simple string, the test passes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions