Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Enzyme Internal Error: Enzyme expects an adapter to be configured, but found none. #131

Closed
@rimatla

Description

@rimatla

Following the documentation of this tutorial the Hello.test.tsx files errors like the title above.

From what I read online, the packages @types/enzyme and react-addons-test-utils would suffice the need to configure an adapter manually on a testsSetup.js

That didn't work.

I took the second route and wrote a testsSetup.js inside my src

setupTests.js (should this be .ts , .tsx?, either way it did not work)

import * as enzyme from 'enzyme';
import * as Adapter from 'enzyme-adapter-react-16';

enzyme.configure({ adapter: new Adapter() });

Hello.test.tsx

import * as React from 'react';
import * as enzyme from 'enzyme';
import Hello from './Hello';

it('renders the correct text when no enthusiasm level is given', () => {
    const hello = enzyme.shallow(<Hello name='Daniel' />);
    expect(hello.find(".greeting").text()).toEqual('Hello Daniel!')
});

Package.json

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.3.1",
    "react-dom": "^16.3.1",
    "react-scripts-ts": "2.14.0"
  },
  "scripts": {
    "start": "react-scripts-ts start",
    "build": "react-scripts-ts build",
    "test": "react-scripts-ts test --env=jsdom",
    "eject": "react-scripts-ts eject"
  },
  "devDependencies": {
    "@types/enzyme": "^3.1.9",
    "@types/enzyme-adapter-react-16": "^1.0.2",
    "@types/jest": "^22.2.2",
    "@types/node": "^7.0.60",
    "@types/react": "^16.3.6",
    "@types/react-dom": "^16.0.4",
    "enzyme": "^3.3.0",
    "enzyme-adapter-react-16": "^1.1.1",
    "react-addons-test-utils": "^15.6.2",
    "typescript": "^2.8.1"
  }
}

Another source suggested adding extra config to jest on package.json such as

........
  "jest": {
    "setupTestFrameworkScriptFile": "<rootDir>/src/setupTests.js"
  }

However that errors as:

These options in your package.json Jest configuration are not currently supported by Create React App:

   setupTestFrameworkScriptFile

Further...
A fresh clone of this repo errors out not running any test suites and complaining about cheerio names.

How can we get the Enzyme Adapter to work with the current project setup on .tsx files?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions