Vue 测试 - '....push 不是函数'
Vue Testing - '... .push is not a function'
我正在尝试测试向现有对象添加新条目的组件方法。
addTag: function () {
this.value[this.field.key].push(this.tag)
this.tag = ''
}
我只是想通过
在我的测试中调用那个方法
wrapper.setProps({
field: {
key: 'tag'
},
value: {
tag: {}
}
})
...
wrapper.vm.addTag()
但它抛出错误
TypeError: this.value[this.field.key].push is not a function
我已经预先设置了所有需要的数据和道具(field.key 和标签),所以这不是问题所在。 运行 其他方法完全没问题,push
似乎是问题所在
这是因为this.value['tag']
是对象,不是数组,所以没有push
方法
将其定义为数组会改变:
wrapper.setProps({
field: {
key: 'tag'
},
value: {
tag: []
}
})
我正在尝试测试向现有对象添加新条目的组件方法。
addTag: function () {
this.value[this.field.key].push(this.tag)
this.tag = ''
}
我只是想通过
在我的测试中调用那个方法 wrapper.setProps({
field: {
key: 'tag'
},
value: {
tag: {}
}
})
...
wrapper.vm.addTag()
但它抛出错误
TypeError: this.value[this.field.key].push is not a function
我已经预先设置了所有需要的数据和道具(field.key 和标签),所以这不是问题所在。 运行 其他方法完全没问题,push
似乎是问题所在
这是因为this.value['tag']
是对象,不是数组,所以没有push
方法
将其定义为数组会改变:
wrapper.setProps({
field: {
key: 'tag'
},
value: {
tag: []
}
})