【问题标题】:Nuxt3 can't import component in testsNuxt3 无法在测试中导入组件
【发布时间】:2022-10-06 14:39:33
【问题描述】:

我正在尝试在 Nuxt 3 上运行组件单元测试,但我收到一条错误消息,告诉我找不到该组件。

失败 test/components/button.test.ts [ test/components/button.test.ts ] 错误:无法解析从“components\Button\Button.vue”导入“@/components/Texts/Button/ButtonText.vue”。文件是否存在?

button.spec.ts

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

test('Button Component', async () => {
    const button = mount(Button, {
        props: {
            text: 'My Test Button'
        }
    });
    expect(button.text()).toEqual('My Test Button');
});

Button.vue

<template>
  <div class="Button">
    <slot name="left" />
    <ButtonText :text="text" />
    <slot name="right" />
  </div>
</template>

<script lang="ts">
export default {
  name: 'Button',
  components: {ButtonText},
  props: {
    // Text to display in the button
    text: {
      type: String as () => string,
      default: 'Button',
      required: true,
    },
  }
}
</script>

有任何想法吗 ?

【问题讨论】:

    标签: vuejs3 nuxtjs3 vitest


    【解决方案1】:

    我有一些问题,如果你解决了这个问题,也请告诉我。谢谢

    【讨论】:

      猜你喜欢
      • 2022-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-26
      • 2018-01-26
      • 2019-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多