6

I get the following error after upgrading to Jest v20 where they removed the automatic babel-polyfill due to memory leaks:

TypeError: Object.values is not a function

I realize I need to polyfill this on my own now, I am using babel-preset-env and have the following .babelrc file:

  "env": {
    "development": {
      "plugins": ["transform-react-jsx-source"]
    },
    "test": {
      "presets": [
        "react",
        "stage-3",
        ["env", {
          "targets": {
            "browsers": [
              "firefox >= 36",
              "chrome >= 38",
              "opera >= 25",
              "safari >= 9",
              "ios >= 9"
            ],
            "node": "6.11.4"
          },
          "useBuiltIns": "usage",
          "include": ["es7.object.values"],
          "debug": true
        }],
        "jest"
      ],
      "plugins": [
        "transform-class-properties"
      ],
    }
  }

I can see that es7.object.values is being polyfilled in the debug output:

Using polyfills:
  ...
  es7.object.values {"chrome":"38","firefox":"36","ios":"9","safari":"9","node":"6.11.4"}

But I am still getting the error message, help!

skyboyer
  • 15,149
  • 4
  • 41
  • 56
Ryan Castner
  • 724
  • 2
  • 8
  • 20

2 Answers2

2

Some of the options are:

  1. bump node version to the one supporting Object.values (which seems to be 7.0 judging from this answer),
  2. polyfill it using babel-polyfill (via import 'babel-polyfill' in setupTests.js file).
Wiktor Czajkowski
  • 1,055
  • 11
  • 19
0

In my case, the Node version was the reason. I just updated the node 6 to node 7 and it fixed.

Behnam Azimi
  • 1,536
  • 1
  • 26
  • 40