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-test-renderer cannot find the render function of the react-native component

See original GitHub issue

Do you want to request a feature or report a bug? A bug

What is the current behavior? When I run my tests and I render my component (using the shallow function of Enzyme) it fails because it can’t find the render function.

 TypeError: this._instance.render is not a function

    > 45 |     wrapper = shallow(<NewEventScreen navigation={navigation} />);
         |               ^
      47 |   });
      48 |

      at ReactShallowRenderer._mountClassComponent (node_modules/react-test-renderer/cjs/react-test-renderer-shallow.development.js:195:37)
      at ReactShallowRenderer.render (node_modules/react-test-renderer/cjs/react-test-renderer-shallow.development.js:143:14)
      at node_modules/enzyme-adapter-react-16/build/ReactSixteenAdapter.js:337:35
      at withSetStateAllowed (node_modules/enzyme-adapter-utils/build/Utils.js:110:16)
      at Object.render (node_modules/enzyme-adapter-react-16/build/ReactSixteenAdapter.js:336:68)
      at new ShallowWrapper (node_modules/enzyme/build/ShallowWrapper.js:170:22)
      at shallow (node_modules/enzyme/build/shallow.js:21:10)
      at Object.<anonymous> (src/screens/new-event/__tests__/NewEventScreen.test.js:45:15)

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn’t have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:

I am developing a react-native application. I am running the default jest command to run the tests and this happens. I can’t reproduce it in a small project.

What is the expected behavior? It should run the tests

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React? I am using: “@babel/core”: “^7.0.0-beta.47”, “prop-types”: “15.6.2”, “react”: “16.4.1”, “react-dom”: “16.4.2”, “react-native”: “0.56.0”, “@babel/core”: “^7.0.0-beta”, “babel-core”: “^7.0.0-beta”, “babel-jest”: “23.4.2”, “babel-preset-react-native”: “5.0.2”, “babel-runtime”: “^7.0.0-beta”, “enzyme”: “3.4.1”, “enzyme-adapter-react-16”: “1.2.0”, “jest”: "23.5.0 ", “jest-fetch-mock”: “1.6.5”, “jsdom”: “11.12.0”, “react-test-renderer”: “16.4.1”,

My jest configuration is in jest.config.js

module.exports = {
  preset: 'react-native',
  setupFiles: ['./jest.setup.js'], // in here i am just loading global.fetch = require('jest-fetch-mock');
};

and my babel config in babel.config.js

module.exports = {
  presets: [
    ['react-native'],
  ],
};

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
evanjmgcommented, Oct 5, 2018

this breaks when i upgrade test renderer from 16.4.2 to 16.5.1. I am also using react native, but I don’t think it has anything to do with that.

1reaction
deecewancommented, Aug 16, 2018

thanks for the tip Dan - it doesn’t seem to work in my case unfortunately. I’ve created an issue over at react-native (https://github.com/facebook/react-native/issues/20683) along with a repo that highlights the regression (https://github.com/deecewan/react-native-jest-regression).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Test Renderer - React
This package provides a React renderer that can be used to render React components to pure JavaScript objects, without depending on the DOM...
Read more >
Using react-test-renderer with <Switch> causes "Stateless ...
Switch is an component provided by react native, I'm afraid I cannot make that stateful. Besides, the warning only pops up in jest....
Read more >
Testing React Native components in Node with react ... - Medium
Below, we will cover rendering elements, testing props, finding nested elements, updating props, and calling event handlers.
Read more >
react-test-renderer - npm
This package provides an experimental React renderer that can be used to render React components to pure JavaScript objects, without depending ...
Read more >
Installation | React Hooks Testing Library
react-test-renderer ; react-dom. When using standard import for this library (show below), we will attempt to auto-detect which renderer ...
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