Vue.js Vue测试Utils:即使道具上的测试通过,也缺少所需道具

Vue.js Vue测试Utils:即使道具上的测试通过,也缺少所需道具,vue.js,vuejs2,vue-test-utils,Vue.js,Vuejs2,Vue Test Utils,我正在用两个按钮构建一个非常基本的增量和减量数量组件,并使用Vue测试Utils编写测试。问题在于,使用所需的道具productId安装组件会生成一条警告,指出productId缺失更奇怪的是wrapper.props('productId')返回我传递的2更奇怪的是,我写的测试通过了 我很乐意将此报告为vue测试utils存储库中的一个bug,但我认为可能有一个简单的解决方案 以下是组件AppGroupButtonItemCartQuantity: + - 从“vuex”导入{mapActi

我正在用两个按钮构建一个非常基本的
增量
减量
数量组件,并使用Vue测试Utils编写测试。问题在于,使用所需的道具
productId
安装组件会生成一条警告,指出
productId
缺失更奇怪的是
wrapper.props('productId')
返回我传递的
2
更奇怪的是,我写的测试通过了

我很乐意将此报告为vue测试utils存储库中的一个bug,但我认为可能有一个简单的解决方案

以下是组件AppGroupButtonItemCartQuantity


+
-
从“vuex”导入{mapActions};
导出默认值{
道具:{
productId:{
类型:字符串,
必填项:true
}
},
计算:{
buttonClass(){
返回“bg-GRY-600文本白色前导无弹性内联ml-1 w-5 h-5四舍五入完整项目中心对齐中心”;
}
},
方法:mapActions(“购物车”[
“incrementProductQuantity”,
“递减产品数量”
])
};
下面是我在AppGroupButtonItemCartQuantity.spec.js中编写的测试:

从“@vue/test-utils”导入{shallowMount,createLocalVue};
从“Vuex”导入Vuex;
从“@/components/AppGroupButtonItemCartQuantity”导入AppGroupButtonItemCartQuantity;
const localVue=createLocalVue();
localVue.use(Vuex);
设wrapper=null,
store=null,
getters=null,
actions=null;
之后(()=>{
wrapper.destroy();
});
描述(“AppGroupButtonItemCartQuantity.vue”,()=>{
在每个之前(()=>{
行动={
incrementProductQuantity:jest.fn(),
递减产品数量:jest.fn()
};
getters={};
store=新的Vuex.store({
模块:{
购物车:{
行动,
获得者,
名称空间:true
}
}
});
});
它(“呈现递增和递减按钮”,()=>{
包装=浅装(AppGroupButtonItemCartQuantity{
localVue,
商店,
propsData:{
productId:“2”
}
});
expect(wrapper.get(“button.incrementquantity”);
expect(wrapper.get(“按钮.减量”);
});
它(“在单击时为给定产品发送递增数量和递减数量操作”,()=>{
包装=浅装(AppGroupButtonItemCartQuantity{
localVue,
商店,
propsData:{
productId:“2”
}
});
expect(wrapper.props(“productId”).toBe(“2”);//通过
expect(actions.incrementProductQuantity).toHaveBeenCalledTimes(0);//通过
const incrementButton=wrapper.get(“button.incrementquantity”);
incrementButton.trigger(“单击”);
期望(actions.incrementProductQuantity).已被调用(
expect.anything(),
"2"
);//通行证
expect(actions.decrementProductQuantity).toHaveBeenCalledTimes(0);//通过
const decrementButton=wrapper.get(“button.decrementquantity”);
递减按钮触发(“点击”);
期望(actions.decrementProductQuantity)已被调用(
expect.anything(),
"2"
);//通行证
});
});
以下是输出:

tests/unit/AppItemCartProduct.spec.js
● 安慰
console.error节点_modules/vue/dist/vue.runtime.common.dev.js:621
[Vue warn]:缺少必需的属性:“productId”
发现于
---> 
测试套件:3个通过,共3个
测试:14项通过,共14项
快照:1个通过,共1个
时间:2.428秒
运行与更改的文件相关的所有测试套件。
手表用法:按w键可显示更多信息。