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

ReferenceError: regeneratorRuntime is not defined with Jest #130

Closed
akana opened this issue Dec 11, 2019 · 2 comments
Closed

ReferenceError: regeneratorRuntime is not defined with Jest #130

akana opened this issue Dec 11, 2019 · 2 comments

Comments

@akana
Copy link

akana commented Dec 11, 2019

I use react-numpad in my React project. It works fine for npm run build and npm start. I use Jest and Enzyme for test. Unfortunately, when i run npm test, i get error of importing react-numpad as below:

ReferenceError: regeneratorRuntime is not defined
      3 | import _ from "lodash";
      4 | import { Trans } from "react-i18next";
    > 5 | import NumPad from "react-numpad";
        | ^
      6 | import Decimal from "decimal.js-light";
      at Object.<anonymous> (node_modules/react-numpad/build/elements/TimeView.js:24:1)
      at Object.<anonymous> (node_modules/react-numpad/build/elements/Calendar.js:28:40)
      at Object.<anonymous> (node_modules/react-numpad/build/elements/index.js:51:40)
      at Object.<anonymous> (node_modules/react-numpad/build/components/Number.js:12:17)
      at Object.<anonymous> (node_modules/react-numpad/build/index.js:8:38)

System

  • OS : Ubuntu 18.04
  • Node : 12.13.1
  • npm : 6.12.1

package.json

{
  "version": "0.1.0",
  "dependencies": {
    "axios": "^0.19.0",
    "bootstrap": "^4.4.1",
    "bootstrap-datepicker": "^1.9.0",
    "change-case": "^3.1.0",
    "check-prop-types": "^1.1.2",
    "i18next": "^14.1.1",
    "immer": "^2.1.5",
    "jquery": "^3.4.1",
    "lodash": "^4.17.15",
    "lodash-humps": "^3.1.5",
    "react": "^16.12.0",
    "react-datepicker": "^2.10.1",
    "react-dom": "^16.12.0",
    "react-i18next": "^10.13.2",
    "react-numpad": "^5.0.4",
    "react-paginate": "^6.3.2",
    "react-redux": "^6.0.1",
    "react-router-breadcrumbs-hoc": "^3.2.4",
    "react-router-dom": "^4.3.1",
    "react-scripts": "^3.3.0",
    "react-select": "^3.0.8",
    "redux": "^4.0.4",
    "redux-orm": "^0.12.4",
    "redux-starter-kit": "^0.4.3",
    "redux-thunk": "^2.3.0",
    "reselect": "^4.0.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "test-watch": "jest --watch",
    "eject": "react-scripts eject",
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "devDependencies": {
    "@babel/core": "^7.7.5",
    "@babel/plugin-transform-runtime": "^7.7.6",
    "@babel/preset-env": "^7.7.6",
    "babel-jest": "^24.9.0",
    "enzyme": "^3.10.0",
    "enzyme-adapter-react-16": "^1.15.1",
    "identity-obj-proxy": "^3.0.0",
    "jest": "^24.9.0",
    "jest-enzyme": "^7.1.2",
    "node-sass": "^4.13.0",
    "react-test-renderer": "^16.12.0",
    "redux-devtools-extension": "^2.13.8",
    "regenerator-runtime": "^0.13.3",
    "sass-loader": "^7.3.1"
  }
}

babel.config.js

module.exports = function(api) {
  api.cache(true);

  const presets = [
    "@babel/preset-react",
    ["@babel/preset-env", { targets: { node: "current" } }]
  ];

  const plugins = [
    "@babel/plugin-transform-runtime",
    "@babel/plugin-proposal-class-properties"
  ];

  return {
    presets,
    plugins
  };
};

jest.config.js

module.exports = {
  moduleNameMapper: {
    "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
      "<rootDir>/__mocks__/fileMock.js",
    "\\.(css|less|sass|scss)$": "identity-obj-proxy"
  },
  transform: {
    "^.+\\.js$": "babel-jest"
  },
  setupFilesAfterEnv: ["<rootDir>/src/setupTest.js"],
  moduleFileExtensions: ["css", "scss", "js", "json", "jsx"],
  testRegex: "/src/.*\\.test\\.js$",
  transformIgnorePatterns: ["/node_modules/(?!test-component).+\\.js$"],
  moduleDirectories: ["src", "node_modules"],
  testEnvironment: "enzyme",
  testEnvironmentOptions: {
    enzymeAdapter: "react16"
  }
};

Any help would be appreciated 😄

@akana
Copy link
Author

akana commented Dec 26, 2019

The problem is solved by import "babel-polyfill"; in setupTests.js. Source

@akana akana closed this as completed Dec 26, 2019
@maxi-gomez
Copy link

Fuente

Gracias crack..! me sirvió te lo agradezco

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants