1
votes

I am using NextJS with Typescript. I am trying to test my application using Jest+Enzyme. I am getting the following error message:

** Test suite failed to run

TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option):
__tests__/Quest.spec.tsx:15:27 - error TS2605:

JSX element type 'Quest' is not a constructor function for JSX elements. Type 'Quest' is missing the following properties from type 'ElementClass': context, setState, forceUpdate, props, refs

**

I have added the code for my Test file and the code for which I have written the test:

Quest.spec.tsx (Test file)

import * as React from 'react';
import {mount} from 'enzyme';
import Quest from '../Quest';

describe('Quest page', () => {
  it('should render without throwing an error', function () {
    const wrapper = mount(<Quest/>);
  })
}) 
1

1 Answers

3
votes

I solved this by: yarn upgrade @types/react@latest and I updated the import statements for both the test.tsx file and my main code file to import * as React from 'react';