
[英]TypeError: Cannot read properties of undefined (reading 'length') JEST test
[英]Jest Vuejs Test - TypeError: Cannot read properties of undefined (reading 'params')
提示:本站为国内最大中英文翻译问答网站,提供中英文对照查看,鼠标放在中文字句上可显示英文原文。
我第一次开始测试我的 vuejs 应用程序。 在我的应用程序中,我有一个客户端列表,当您单击客户端时,您将 go 转到该客户端页面,我现在正在尝试对其进行测试。 但是在我开始出现这个错误之前我的测试失败了:
TypeError: Cannot read properties of undefined (reading 'params')
created() {
this.clientid = this.$route.params.id;
^
this.getClient();
}
我试图将其设置为我的测试:
describe('Client', () => {
it('should mount Client', () => {
const wrapper = mount(Client, {
data: () => ({
route: {
params: {
id: ''
}
},
}),
});
expect(wrapper.exists()).toBe(true);
});
});
你能帮我理解如何通过测试给这个参数赋值吗?
.net 上有很多不同的答案,但是对于 vue1. 这对我有用:
describe('Client', () => {
it('should mount Client', async () => {
const wrapper = shallowMount(Client, {
global: {
mocks: {
$route: {params: { id: ""}},
}
}
})
expect(wrapper.exists()).toBe(true);
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.