Reputation: 298
I have a problem with unit test to trigger click. Error: Expected: 1, Received: 0 I'm using Vue, Jest and Vue test utils. I wanna test if the button is triggered
Search.vue
<v-btn id="searchBtn" @click="searchItem"></v-btn>
methods: {
searchItem() {}
...
}
test.spec.js
import Search from '...'
describle(Search, () => {
it('trigger button', () => {
const wrapper = shallowMount(Search)
const clickMethodStub = jest.fn()
wrapper.setMethods({ searchItem: clickMethodStub })
wrapper.find('#searchBtn').trigger('click')
expect(clickMethodStub.mock.calls.length).toBe(1)
})
})
}
Error: Expected: 1 Received: 0
Upvotes: 1
Views: 696
Reputation: 340
Because it is vuetify button, you need to use to shallowMount
to mount
.
import Search from '...'
describle(Search, () => {
it('trigger button', () => {
const wrapper = mount(Search)
const clickMethodStub = jest.fn()
wrapper.setMethods({ searchItem: clickMethodStub })
wrapper.find('#searchBtn').trigger('click')
expect(clickMethodStub.mock.calls.length).toBe(1)
})
})
}
Upvotes: 1