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

Error: Object.fromEntries is not a function #6929

Closed
balazsorban44 opened this issue Apr 26, 2019 · 1 comment
Closed

Error: Object.fromEntries is not a function #6929

balazsorban44 opened this issue Apr 26, 2019 · 1 comment

Comments

@balazsorban44
Copy link
Contributor

Hi! I have a beginner question.

The following:

it("Object.fromEntries", () => {
  expect(Object.fromEntries([["a", 1]])).toEqual({a: 1})
})

Throws this error:

console.error node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/virtual-console.js:29 Error: Uncaught [TypeError: Object.fromEntries is not a function]
I use CRA 3.0, but I tried in a previous version, and did not work either.

I am interested in the reason why this does not work?

Adding this: Object.fromEntries = l => l.reduce((a, [k,v]) => ({...a, [k]: v}), {}) to the test file solves the issue, but I just would like to understand the reason why I need it.

Thanks!

@ianschmitz
Copy link
Contributor

ianschmitz commented Apr 27, 2019

The reason is that function isn't implemented yet in node. https://kangax.github.io/compat-table/es2016plus/ is a good resource to see the support of newer APIs in different browsers and node versions.

You can either use a polyfill or avoid using the API until it is has better support.

@lock lock bot locked and limited conversation to collaborators May 2, 2019
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

2 participants