Vue模板在测试中没有正确绑定
问题描述:
我有一个简单的按钮组件,我想用vue-test-utils
,mocha-webpack
和jsdom
来测试。Vue模板在测试中没有正确绑定
const Button = {
props: {
text: {default: 'Save draft'}
},
data: function() {
return {
disabled: false
}
},
template: `
<input
v-bind:value='text'
v-bind:disabled='disabled'
type='submit' name='save' class='highlight'
>
`
}
export default Button
一切都在浏览器中正常工作,但没有我的v-bind
属性在我的测试中被渲染:
describe('Button',() => {
it('has the right text',() => {
const wrapper = mount(SaveDraftButton, {})
wrapper.update()
console.log(wrapper.html())
expect(wrapper.hasAttribute('value', 'Save draft')).to.be.true
})
})
的console.log
输出<input type="submit" name="save" class="highlight">
。
非属性绑定(例如<p>{{ text }}</p>
)正常工作。
任何人都可以建议我在这里做错了吗?这似乎是最简单的事情,我正在反对它。
[看起来这是一个错误(https://forum.vuejs.org/t/v-bind-not-working-with-attributes-in-test/19894/ 4)在'jsdom'或'vue-test-utils'中。 – velvetkevorkian