I have a simple function in actions.js file:
import Vue from 'vue'
const actions = {
foo() {
// someting else
console.log(Vue.$communicates.display) // prints mocked function, so OK
Vue.$communicates.display('foo') // my plugin
}
}
export default actions
now I want to mock 'vue' and detect if display function has been called. I wrote test in actions.spec.js:
jest.mock('vue', () => ({
$communicates: {
display: jest.fn()
}
}))
import Vue from 'vue'
import actions from './actions.js'
describe('test', () => {
it('should display communicate', () => {
actions.foo()
expect(Vue.$communicates.display).toHaveBeenCalled()
})
})
And this code gives me an error:
Expected mock function to have been called, but it was not called.
I do not understand why.
Aucun commentaire:
Enregistrer un commentaire