【发布时间】:2018-10-30 10:51:13
【问题描述】:
vue-test-utils 提供了一个 setComputed 方法,允许您设置计算属性的状态。
import { mount } from '@vue/test-utils'
const wrapper = mount(Home)
wrapper.setComputed({loaded: true})
vue-test-utils 版本 1.1.0.beta 对读取为 setComputed() has been deprecated and will be removed in version 1.0.0. You can overwrite computed properties by passing a computed object in the mounting options 的 setComputed 方法发出弃用警告
mounting options in the docs 没有提及任何计算对象。我试了一下
const wrapper = mount(Home, { computed: {loaded: true} })
和
const wrapper = mount(Home, {context: { computed: {loaded: true} } })
但是那些爆炸了。
为 vue-test-utils 设置计算属性的方法是什么?
【问题讨论】:
标签: unit-testing vuejs2 vue-test-utils