I'm testing component ComponentA.spec.js and I get TypeError: Cannot read property 'type' of null
. If I remove the wait keyword in the getData() function in ComponentA, it works. I mocked the getData api call in my test but it still doesn't work.
This is the complete stack TypeError: C: [Privacy]\Unknown: Cannot read property 'type' of null
at assert (node_modules/@babel/types/lib/asserts/generated/index.js:284:112) at Object.assertIdentifier (node_modules/@babel/types/lib/asserts/generated/index.js:373:3) at new CatchEntry (node_modules/regenerator-transform/lib/leap.js:93:5) at Emitter.Ep.explodeStatement (node_modules/regenerator-transform/lib/emit.js:535:36) at node_modules/regenerator-transform/lib/emit.js:323:12 at Array.forEach () at Emitter.Ep.explodeStatement (node_modules/regenerator-transform/lib/emit.js:322:22) at Emitter.Ep.explode (node_modules/regenerator-transform/lib/emit.js:280:40)
This is the component I'm trying to create a test for, A
This is my ComponentA.spec.js file
import Vuetify from 'vuetify'; import ComponentA from 'components/ComponentA'; import { createLocalVue, shallowMount, mount } from '@vue/test-utils'; jest.mock('shared/apis', () => { const data = require('../fixedData/data.json'); return { getData: jest.fn().mockResolvedValue(data), }; }); const localVue = createLocalVue(); let vuetify; function createShallowWrapper(options = {}) { return shallowMount(ComponentA, { localVue, vuetify, ...options, }); } beforeEach(() => { vuetify = new Vuetify(); }); describe('ComponentA', () => { describe('component creation', () => { test('testing', () => { const wrapper = createShallowWrapper(); expect(wrapper).toMatchSnapshot(); }); }); });
Adding the exception variable (e) to the capture in the getData function in ComponentA fixed the issue.