[Vuejs]-How to call a function in Jest with a specific value?

0👍

In order to cover your test case, you need to mock testFunctionA before you call setProps({testData2: null}). That’s because wrapper.setProps(...) is what triggers the evaluation of testFunctionB:

it('should disable the input when the testData2 value is not defined and the testFunctionA is true', async () => {
 jest.spyOn(wrapper.vm, 'testFunctionA').mockReturnValueOnce(true);
 await wrapper.setProps({testData2: null});
 expect(wrapper.vm.testFunctionB).toBe(true);
})

Leave a comment