React.Fragment throws an error on shallow render
See original GitHub issueHi, 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:
- Created 4 years ago
- Reactions:2
- Comments:12 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@akashuba your workaround could be
shallow(<div>{modalState.done.description}</div>).text()
, i suspectThanks! I think it might be quite useful… In the meantime I have a workaround, though so it’s not a pressing issue for me.