Skip to content

Instantly share code, notes, and snippets.

@balataca
Last active December 12, 2018 10:49
Show Gist options
  • Save balataca/f114460759874e85adfed73e3beb72cd to your computer and use it in GitHub Desktop.
Save balataca/f114460759874e85adfed73e3beb72cd to your computer and use it in GitHub Desktop.
Test method inside Vuejs mounted lifecycle hook with Jest
import { mount } from '@vue/test-utils'
import Component from '.'
describe('Component', () => {
describe('mounted', () => {
let wrapper
let spy
beforeEach(() => {
spy = jest.spyOn(Component.methods, 'methodToMock')
wrapper = mount(Component)
})
afterEach(() => {
spy.mockClear()
})
it('should call method methodToMock', () => {
expect(spy).toHaveBeenCalled()
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment