Skip to content

react-test-renderer returns TypeError: (0 , _typeof4.default) is not a function #15886

@nishant-dani

Description

@nishant-dani

Do you want to request a feature or report a bug?
It is a bug report

What is the current behavior?
While running my jest tests I am facing the following problem:

 FAIL  src/components/Campaigns/CampaignForm/__tests__/CampaignForm.test.js
 Test suite failed to run

    TypeError: (0 , _typeof4.default) is not a function

      1 | import React from 'react'
      2 | import renderer from 'react-test-renderer'
        | ^

I have examined the stack.

      at _typeof2 (node_modules/@babel/runtime/helpers/typeof.js:2:39)
      at _typeof2 (node_modules/@babel/runtime/helpers/typeof.js:15:39)
      at node_modules/react-test-renderer/node_modules/scheduler/cjs/scheduler.development.js:61:31

If I open the files and see what is at the line numbers on the new files; this is what I have;

      at _typeof2 (node_modules/@babel/runtime/helpers/typeof.js:2:39)
function _typeof2(obj) {
  if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
    _typeof2 = function _typeof2(obj) {

      at _typeof2 (node_modules/@babel/runtime/helpers/typeof.js:15:39)
function _typeof(obj) {
  if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") {

      at node_modules/react-test-renderer/node_modules/scheduler/cjs/scheduler.development.js:61:31
var hasNativePerformanceNow = typeof performance === 'object' && typeof performance.now === 'function';

So the react-test-renderer typeof call is getting redirected (possibly by babel) to a babel helper function for typeof, which is giving the error.

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:

What is the expected behavior?
It should testing my jest tests.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
I am running this on mac on the command line. Using npm run test which defaults to running jest in package.json. I am using babel 7.0.0 version. Any guidance on how I might debug this further would be great. Happy to debug but would need some pointers on where to look for the issue. I searched for typeof4 in @babel but there is no string.
Very superficially, (and I could be wrong) I suspect that babel is transpiling the regenerator runtime and when it does it ends up on this problem.
Thanks for any help that will unblock me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions