Mocking methods on a Vue instance during TDD

Solution 1: jest.spyOn(Component.methods, ‘METHOD_NAME’) You could use jest.spyOn to mock the component method before mounting: import MyComponent from ‘@/components/MyComponent.vue’ describe(‘MyComponent’, () => { it(‘click does something’, async () => { const mockMethod = jest.spyOn(MyComponent.methods, ‘doSomething’) await shallowMount(MyComponent).find(‘button’).trigger(‘click’) expect(mockMethod).toHaveBeenCalled() }) }) Solution 2: Move methods into separate file that could be mocked The official recommendation is … Read more

tech