unit-testing - 运行单元测试时出现“Vue 类型不存在属性‘扩展’”错误
问题描述
我创建了一个 Vue 组件和一个单元测试来验证它的行为。我可以在我的 Vue 应用程序上使用该组件而没有任何问题,但是当我使用 jest 运行我的单元测试时,我得到了错误:
error TS2339: Property 'extend' does not exist on type 'typ
eof import("</path/to/module>")'.
1 export default Vue.extend({
vButton.ts - 被测组件
export default Vue.extend({
template: `
<div>
<button class="default-button" @click="click">
<span>{{ text }}</span>
</button>
</div>
`,
props: {
text: String,
action: Function
},
methods: {
click(): void {
this.$emit('action');
}
}
});
vButton.spec.ts - 单元测试
import { mount } from '@vue/test-utils'
import vButton from '../views/core/ts/components/vButton'
describe('vButton', () => {
describe(':props', () => {
it(':text - should render a button with the passed-in label text', () => {
const msg = 'new message';
const wrapper = mount(vButton, {
propsData: { text: msg },
});
expect(wrapper.text()).toMatch(msg);
});
});
describe('@events', () => {
it('@click - should emit an "action" event when the button is clicked', () => {
const wrapper = mount(vButton);
const button = wrapper.find('button')
button.trigger('click')
expect(wrapper.emitted().action).toBeTruthy()
})
});
});
我希望 Vue.extend 在运行单元测试时能够正常工作。
解决方案
推荐阅读
- flutter - 如何在颤振应用程序中将分隔线扩展到整个窗口宽度?
- javascript - 循环遍历动态表时遇到问题
- python - QLineEdit 更改 PlaceholderText 颜色
- microsoft-graph-api - 如何在 msgraph-sdk-dotnet-auth 身份验证提供程序中设置 MaxRetry 值
- gsm - 配置 NetworkManager 以在蜂窝连接处于活动状态时通过 WiFi 路由本地 wlan 数据以进行调试
- gnucobol - GnuCOBOL 微不足道的“回声”功能
- python - 更改熊猫数据框中的数据类型更改过滤结果
- r - 在 R 中写入 excel 文件时创建粗体列名(列名)
- css - 如何使用tailwindcss更改悬停宽度
- javascript - 不和谐中的自动角色分配