0
我有一個簡單的按鈕組件,我想用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