的“V型秀”属性时,你有显示了基于模型的按钮,像这样:如何单元测试的Vue组件
<button v-show="title != ''">Add it</button>
你会如何测试这个?我无法想象出我的生活。
我尝试了以下(使用玩笑,但亚军/框架不应该的问题):
describe('btn test',() => {
it('should hide the add button initially',() => {
// vm is set up here to be the vue component
expect(vm.$el.querySelector('button').style.display).toBe('none') // works
// Update the input field (which has v-model="title")
vm.$el.querySelectorAll('input').value = 'fd'
expect(vm.$el.querySelector('button').style.display).toBe('block') // is still 'none'
// Update directly through vm prop
vm.title = 'sheep'
Vue.nextTick(() => {
expect(vm.$el.querySelector('button').style.display).toBe('block') // is still 'none'
})
})
})
但我确实在我上面的例子(第14行),但没有按”不要做诡计 – Hyra