Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'render' of undefined enzyme-adapter-react-14 #1667

Closed
wKich opened this issue May 31, 2018 · 5 comments
Closed

Comments

@wKich
Copy link

wKich commented May 31, 2018

Describe the bug
Using stateless arrow functional component lead to an error.

To Reproduce

  1. Execute code:
import Enzyme, { mount } from 'enzyme'
import Adapter from 'enzyme-adapter-react-14'

Enzyme.configure({ adapter: new Adapter() })

const Bar = () => <div>{'Hello'}</div>
class Foo extends React.Component {
  render() { return <Bar /> }
}
mount(<Foo />)
  1. See error:
TypeError: Cannot read property 'render' of undefined
  at typeToNodeType (node_modules/enzyme-adapter-react-14/build/ReactFourteenAdapter.js:49:31)
  at instanceToTree (node_modules/enzyme-adapter-react-14/build/ReactFourteenAdapter.js:85:17)
  at instanceToTree (node_modules/enzyme-adapter-react-14/build/ReactFourteenAdapter.js:91:17)
  at instanceToTree (node_modules/enzyme-adapter-react-14/build/ReactFourteenAdapter.js:91:17)
  at Object.getNode (node_modules/enzyme-adapter-react-14/build/ReactFourteenAdapter.js:149:33)
  at new ReactWrapper (node_modules/enzyme/build/ReactWrapper.js:100:33)
  at mount (node_modules/enzyme/build/mount.js:19:10)
  at Context.it (test.js:10:5)

Expected behavior
Code should works without error.

Desktop (please complete the following information):

  • OS: OSX 10.13.4
  • Browser: jsdom
  • Version: 11.1.0

Additional context

  • enzyme: 3.3.0
  • enzyme-adapter-react-14: 1.0.5
  • react: 0.14.9
@mykhailo-riabokon
Copy link
Contributor

Hi @wKich

I have tried your configuration and did not get an error. I created a repository with your case could you please check? Maybe something is missing. Also, I noticed that you do not have React in your Execute code.

@wKich
Copy link
Author

wKich commented Jun 9, 2018

Yeah, sure. import React from 'react' should be.

In your example, you use babel-preset-env without options, so arrow functions will transform to normal function and test failed, because error throw is only when you use arrow function. If you change .babelrc to like this:

{
  "presets": ["react"],
  "plugins": ["transform-es2015-modules-commonjs"]
}

Test will pass.

@mykhailo-riabokon
Copy link
Contributor

@wKich In this case I see a few workarounds here:

{
  "presets": ["react"],
  "plugins": ["transform-es2015-modules-commonjs"]
}
  • use env preset which is more flexible than trying to cover your needs by plugins. You can specify your desirable target(s) and voilà
  • React 0.14.9 is a bit old, and if you can switch to a newer version you will not have this issue with your initial .babelrc. I pushed this version to this branch.

I hope it helps you.

@wKich
Copy link
Author

wKich commented Jun 10, 2018

Thank you for workaround options, but I just wanted to report about this issue

@ljharb
Copy link
Member

ljharb commented Jun 29, 2018

@wKich Thanks - I was able to reproduce this, and find a fix as well as add a regression test. I'll push up a fix shortly.

ljharb added a commit that referenced this issue Jun 29, 2018
ljharb added a commit that referenced this issue Jun 29, 2018
@ljharb ljharb closed this as completed in c18638b Jun 29, 2018
ljharb added a commit that referenced this issue Jul 9, 2018
 - [fix] call ref for a root element (#1541)
 - [fix] Allow empty strings as key props (#1524)
 - [fix] Allow empty strings as key props
 - [fix] correct the adapter class name
 - [fix] `mount`: make sure it works with native arrow functions (#1667)
 - [refactor]: add “lifecycles” adapter option (#1696)
 - [refactor] use `react-is` package
 - [deps] remove unneeded `lodash` dep; update `prop-types`, `enzyme-adapter-utils`, `object.assign`
 - [dev deps] update `babel-cli`, `babel-core`, `babel-plugin-transform-replace-object-assign`, `babel-preset-airbnb`, `chai`, `coveralls`, `eslint`, `eslint-config-airbnb`, `eslint-plugin-import`, `eslint-plugin-jsx-a11y`, `eslint-plugin-react`, `lerna`, `json-loader`, `karma-firefox-launcher`, `prop-types`, `lerna`, `rimraf`, `webpack`
ljharb added a commit that referenced this issue Jul 9, 2018
 - [fix] actually invoke the setState callback (#1465, #1453)
 - [fix] add missing support for animation events (#1569)
 - [fix] call ref for a root element (#1541)
 - [fix] Allow empty strings as key props (#1524)
 - [fix] correct the adapter class name
 - [fix] `mount`: make sure it works with native arrow functions (#1667)
 - [refactor]: add “lifecycles” adapter option (#1696)
 - [refactor] use `react-is` package
 - [deps] remove unneeded `lodash` dep; update `prop-types`, `enzyme-adapter-utils`, `object.assign`
 - [dev deps] update `babel-cli`, `babel-core`, `babel-plugin-transform-replace-object-assign`, `babel-preset-airbnb`, `chai`, `coveralls`, `eslint`, `eslint-config-airbnb`, `eslint-plugin-import`, `eslint-plugin-jsx-a11y`, `eslint-plugin-react`, `lerna`, `json-loader`, `karma-firefox-launcher`, `prop-types`, `lerna`, `rimraf`, `webpack`
ljharb added a commit that referenced this issue Jul 9, 2018
 - [fix] actually invoke the setState callback (#1465, #1453)
 - [fix] add missing support for animation events (#1569)
 - [fix] call ref for a root element (#1541)
 - [fix] Allow empty strings as key props (#1524)
 - [fix] correct the adapter class name
 - [fix] `mount`: make sure it works with native arrow functions (#1667)
 - [refactor]: add “lifecycles” adapter option (#1696)
 - [refactor] use `react-is` package
 - [deps] remove unneeded `lodash` dep; update `prop-types`, `enzyme-adapter-utils`, `object.assign`
 - [dev deps] update `babel-cli`, `babel-core`, `babel-plugin-transform-replace-object-assign`, `babel-preset-airbnb`, `chai`, `coveralls`, `eslint`, `eslint-config-airbnb`, `eslint-plugin-import`, `eslint-plugin-jsx-a11y`, `eslint-plugin-react`, `lerna`, `json-loader`, `karma-firefox-launcher`, `prop-types`, `lerna`, `rimraf`, `webpack`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants