DefinePageMeta将如何在vitest上嘲笑?
我正在尝试 vitest 为我的应用程序编写UTS,该应用在VUE顶部具有NUXT。
但是,当试图模拟test.vue
时,我会得到定义
的定义。
这是我的 component test.vue
-
<script setup lang="ts">
definePageMeta({
layout: 'xyz',
title: 'test component',
});
</script>
<template>
<div>
<h1>Hello World</h1>
</div>
</template>
这是我的UT文件,名为test.spec.ts
如下 -
import { describe, expect, it } from 'vitest';
import Index from '../pages/test.vue';
import { mount } from '@vue/test-utils';
describe('renders the test component', () => {
it('renders properly', () => {
const wrapper = mount(Index);
expect(wrapper.text()).toContain('Hello Vitest');
});
});
这是我得到的错误-
I was trying Vitest to write UTs for my app which has Nuxt on the top of Vue.
But I am getting definePageMeta
as undefined when trying to mock test.vue
.
Here is my component test.vue
-
<script setup lang="ts">
definePageMeta({
layout: 'xyz',
title: 'test component',
});
</script>
<template>
<div>
<h1>Hello World</h1>
</div>
</template>
Here is my UT file named test.spec.ts
as follows -
import { describe, expect, it } from 'vitest';
import Index from '../pages/test.vue';
import { mount } from '@vue/test-utils';
describe('renders the test component', () => {
it('renders properly', () => {
const wrapper = mount(Index);
expect(wrapper.text()).toContain('Hello Vitest');
});
});
Here is the Error I am getting -
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以找到答案 stackoverflow defin”> shere stackoverflow atect stackoverflow问题
:import {definepagemeta}从'#imports''
添加此resolve.alias.alias和setupfiles以及setUpfiles
,最后将其添加到setup-tests.js。
基本上导入以下内容 深度信息
the answer can be found here stackoverflow question
Basically import this: import { definePageMeta } from '#imports'
Add this resolve.alias to vitest.config.js, as well as the setupFiles
And finally add this to setup-tests.js
Follow the link above for more in-depth info