I have simple component which triggers function 'display' on $communicates object. I want to be sure that this function have been called:
it('should display communicate', () => {
const $communicates = {
display() { return true }
}
const wrapper = shallowMount(Component, {
mocks: {
$communicates
}
})
const spy = jest.spyOn(wrapper.vm.$communicates, 'display')
// const spy = jest.spyOn($communicates, 'display') //also tried
// ... code which triggers component method 'displayCommunicate' ...
expect(spy).toHaveBeenCalled()
})
and my component:
export default {
methods: {
displayCommunicate() {
console.log('function executed') // 'function executed'
this.$communicates.display('Blabla')
}
}
}
Jest shows me error
Expected mock function to have been called, but it was not called.
Aucun commentaire:
Enregistrer un commentaire