vuejs / test-utils

Vue Test Utils for Vue 3
https://test-utils.vuejs.org
MIT License
1.05k stars 245 forks source link

Bug: Cannot destructure property 'createComponentInstance' of 'ssrUtils' as it is undefined. #2506

Closed zhaoguangyue closed 2 months ago

zhaoguangyue commented 2 months ago

The following is correct, no errors reported:

import HelloWorld from './HelloWorld.vue';
import { mount } from '@vue/test-utils';

Errors will be reported below: TypeError: Cannot destructure property 'createComponentInstance' of 'ssrUtils' as it is undefined.

import { mount } from '@vue/test-utils';
import HelloWorld from './HelloWorld.vue';

They just reversed the order

Here is the case: // helloworld.test.ts

import { expect, test } from 'vitest';
import { mount } from '@vue/test-utils';
import HelloWorld from './HelloWorld.vue';

test('renders name', async () => {
  const wrapper = await mount(HelloWorld, {
    props: { name: 'Vitest' }
  });
  const element = wrapper.find('.aaa');
  expect(element.exists()).toBe(true);
});

//HelloWorld.vue

<template>
  <div class="aaa">
    <h1>Hello {{ name }}!</h1>
  </div>
</template>

<script setup lang="ts">
defineProps<{
  name: string
}>();
</script>

environment: vitest Official demo https://cn.vitest.dev/guide/browser/

  1. pnpx vitest init browser
  2. remove @testing-library/vue and use @vue/test-utils