enzymejs/enzyme

React.Fragment throws an error on shallow render

Open

#2327 opened on Feb 6, 2020

View on GitHub
 (12 comments) (2 reactions) (0 assignees)JavaScript (19,979 stars) (2,016 forks)batch import
API: shallowhelp wanted

Description

Hi, this seems like a potentially common issue but I haven't found anything directly addressing it. Enzyme seems to throw the error: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was symbol.

when trying to wrap React.Fragment with shallow.

Test code:

import React from 'react';

import Adapter from 'enzyme-adapter-react-16';
import { configure, shallow } from 'enzyme';
configure({ adapter: new Adapter() });

describe('test', () => {

  it('case', () => {
    shallow(<React.Fragment>test</React.Fragment>);
  });

});

My package.json is:

{
  "name": "enzyme",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "devDependencies": {
    "@babel/preset-env": "^7.8.4",
    "@babel/preset-react": "^7.8.3",
    "babel-jest": "^25.1.0",
    "enzyme": "^3.11.0",
    "enzyme-adapter-react-16": "^1.15.2",
    "jest": "^25.1.0",
    "react": "^16.12.0",
    "react-test-renderer": "^16.12.0"
  },
  "scripts": {
    "test": "jest"
  },
  "dependencies": {
    "react-dom": "^16.12.0"
  }
}

Contributor guide