I'm using the Buefy CSS Framework, which provides custom vue-js components such as <b-input>
and <b-table>
, and I've come across a problem testing the <b-input>
tag.
import { shallowMount, createLocalVue } from '@vue/test-utils'
import BInputPractice from '../BInputPractice.vue'
import Buefy from 'buefy'
const localVue = createLocalVue()
localVue.use(Buefy)
describe('b-input Practice', () => {
it('updates the name data property', () => {
const wrapper = shallowMount(BInputPractice, {
localVue,
stubs: {
'b-input': Buefy.Input
}
})
const input = wrapper.find('input')
input.element.value = 'a name'
input.trigger('input')
expect(wrapper.vm.name).toBe('a name')
})
})
<!-- BInputPractice.vue -->
<template>
<div>
<b-input v-model="name"></b-input>
<!-- <input v-model="name"> -->
</div>
</template>
<script>
export default {
data() {
return {
name: ''
}
}
}
</script>
The expect statement in my test code should pass, as it passes when I use an <input>
tag instead of a <b-input>
. However, triggering the 'input' event on the <b-input>
does nothing to the name
data property.
Does anyone know how I can correctly stub the <b-input>
tag so that I can test it exactly as an <input>
tag?