question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React.Fragment throws an error on shallow render

See original GitHub issue

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"
  }
}

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ljharbcommented, Aug 27, 2021

@akashuba your workaround could be shallow(<div>{modalState.done.description}</div>).text(), i suspect

1reaction
andrewplummercommented, Feb 7, 2020

Thanks! I think it might be quite useful… In the meantime I have a workaround, though so it’s not a pressing issue for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest Shallow Component Testing Error "Cannot read property ...
I want to shallow render a component and check to see if it doesn't crash. The docs tells me that shallow rendering doesn't...
Read more >
React Tips and Tricks — Fragments and Error Handling
We wrap error boundary components around components that may throw errors for them to work. Error boundary components are always class-based ...
Read more >
React Top-Level API
React also provides a component for rendering multiple elements without a wrapper. React.Fragment ... Otherwise this method throws an error. Note: React.
Read more >
Shallow Renderer - React
When writing unit tests for React, shallow rendering can be helpful. Shallow rendering lets you render a component “one level deep” and assert...
Read more >
Test Renderer - React
This package provides a React renderer that can be used to render React components ... one test instance with the provided props ,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found