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: Object.values is not a function #3687

Closed
sibelius opened this issue May 30, 2017 · 13 comments
Closed

TypeError: Object.values is not a function #3687

sibelius opened this issue May 30, 2017 · 13 comments

Comments

@sibelius
Copy link

My tests works fine on Jest 19.0.0, but it breaks when I upgrade to Jest 20.0.4 with the following error:

TypeError: Object.values is not a function

this is my .babelrc:

{
  "presets": ["flow", "es2015", "stage-0"]
}

this is the code that breaks:

Object.values(USERS_ROLES)

@cpojer
Copy link
Member

cpojer commented May 30, 2017

We don't require babel-polyfill automatically any more because it lead to memory leaks. Please call it yourself in setupFiles.

@cpojer cpojer closed this as completed May 30, 2017
@jsg2021
Copy link

jsg2021 commented Jun 7, 2017

@cpojer Is this documented somewhere?

@kmiyashiro
Copy link

kmiyashiro commented Jun 8, 2017

I've tried import 'babel-polyfill in a standalone test setup file and added to setupFiles, but I still get this error. If I run jest --no-cache, it works. If I run jest --findRelatedTests immediately after which runs the same tests, it does not work. 😕

@lvela
Copy link

lvela commented Jun 16, 2017

I'm running into the same issue. Found that it fails in some versions of node. Tests passed using 7.10.0 but not 6.10.3.

I also got it to work with the older version of node by adding to package.json

    "unmockedModulePathPatterns": [
      "<rootDir>/node_modules/babel-polyfill/",
      ...
    ]

and then in my test file adding:

import 'babel-polyfill'

If need to dig into the issue more, look at changes from #2755

@noahbenham
Copy link

noahbenham commented Jun 28, 2017

This is also causing test failures for us, running node v6.10.3. @lvela's solution (and the one originally posted by @cpojer) worked without needing to unmock babel-polyfill.

This should probably be updated in the docs if this is an expectation for developers.

@SimenB
Copy link
Member

SimenB commented Jun 28, 2017

Why do you need to document "if you call functions in an environment which does not support it, you have to polyfill it"? It makes perfect sense, and it's the same thing you would do if you use Object.values in the browser today.

@jsg2021
Copy link

jsg2021 commented Jun 29, 2017

@SimenB I agree, but the polyfills were called on by Jest before. Now they're not. It's in the changelog as a breaking change, that satisfied me once I was pointed to it. :) Kind of a subtle line tho... could have been bolder ;)

@JakeRuth
Copy link

Just stumbled upon this thread with the same issue, if it helps anyone here's how I fixed it:
Installed npm package object.values: https://www.npmjs.com/package/object.values
Here's my setupFiles:

    "setupFiles": [
      "<rootDir>/config/polyfills.js"
    ],

In polyfills.js I add the following line:

Object.values = require('object.values');

What this does I believe is tell Jest that when Object.values is called, use the implementation in the npm package that should mirror the behavior of the real Object.values

@jimjkelly
Copy link

For those reluctant to install a dependency just for this, you can also add this to your setupFile:

Object.values = (obj) => Object.keys(obj).map(key => obj[key])

@Anthony-Mckale
Copy link

I put a simple require in a other wise empty setup file, and it worked fine, had the babel polyfill used for older browsers anyway

aurelia-jest-bl-bootstrap.js

// https://github.com/facebook/jest/issues/3687 require('babel-polyfill');

jest-bl-cli-version.json

{ ... "setupFiles": [ "../test/aurelia-jest-bl-bootstrap.js" ], "modulePaths": [ "../src", "../node_modules" ], "moduleFileExtensions": [ "js", "json" ], "moduleNameMapper": { "aurelia-(.*)": "../node_modules/$1", "(.*)/ft-(.*)": "../src/$1/ft-$2" } }

@Shelob9
Copy link

Shelob9 commented Jun 30, 2018

I got the same error message, when running tests in Travis, which passed locally but failed in CI and landed here. I found a different solution I'd just like to share so I or anyone else can find it later.

In my case, I was testing with node 6.10.something and Stack Overflow pointed out that Object.values is not a function in node 6, but it is in 7. So I switched to 7, but yarn doesn't work with 7, so I switched to Node 8, which works.

In .travis.yml

node_js:
  - "7"

@nik-john
Copy link

nik-john commented Aug 6, 2019

If anyone runs into this and can't figure out why, look to see if you are running an older version of Node

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests