-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Object.entries is not a function when importing react-testing-library #110
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
Comments
For people who can't upgrade: install and import the babel-polyfill in your test files.
|
I guess it wouldn't harm to use |
To be clear, I'm not using |
Yes I know. What I suggested was regarding the code in this library, that maybe that code could with to use |
Considering Node 6 is on maintenance LTS, I don't care to support it anymore. We should update our engines config in package.json. |
🎉 This issue has been resolved in version 3.1.7 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Hi guys, sorry if i'm not doing this right. I happen to encounter this problem again. All my node, npm and react-testing-library is all up to date. The solution I am using right now is importing babel-polyfill |
Hmmmm.... Could you create a simple reproduction repository? |
Amazingly now I can't replicate the error even after totally removing the babel-polyfil, ahhaha. Can't really say anything much right now, just sorry for the noise. Most probably it is because I accidentally installed jest-cli over CRA but then later I decide to remove, install and update everything. Cheers |
Hi @kentcdodds I'm getting this issue import React from 'react';
import { render, cleanup, fireEvent } from 'react-testing-library';
import Button from '../';
afterEach(cleanup);
test('renders the button component', () => {
const { container } = render(<Button>CLICK ME</Button>);
expect(container).toMatchSnapshot();
});
test('Handle Click', () => {
const handleClick = jest.fn();
const { getByText } = render(<Button onClick={handleClick}>SUBMIT</Button>);
fireEvent.click(getByText('SUBMIT'));
expect(handleClick).toHaveBeenCalledTimes(1);
}); I am running these tests as part of a precommit hook. My package.json is as shown {
... Other things
"scripts": {
"test": "node scripts/custom-config test --env=jsdom",
"test:staged": "cross-env CI=true node scripts/custom-config test --env=jsdom --findRelatedTests",
"precommit": "lint-staged",
},
"lint-staged": {
"**/src/**/*.js": [
"prettier --write",
"eslint --fix",
"npm run test:staged",
"git add"
]
},
} I am using node 8.1.2 and react-testing-library is on 5.0.1 |
That shouldn't be happening. In your test do this: console.log(process.version)
console.log(Object.entries) My guess is that your system is on a recent version of node, but somehow your tests are being run with an older version. |
Did some digging.. Turns out husky was running the precommit script with some random old node version (6.9.4), not the same as my system, solved it by doing the following nvm alias default 8.12.0 |
My guess is that you have an |
Naa, the library had some issues as enlisted here typicode/husky#77 |
react-testing-library doesn't support it testing-library/react-testing-library#110
Reporting this as an issue along with the fix in hopes that it helps others find the answer quicker.
Problem
When importing
react-testing-library
and running my tests, they failed with the following errorVersion Information
react-testing-library
version: 3.1.4react
version: N/Anode
version: 6.xnpm
(oryarn
) version: 6.xSolution
Per @kentcdodds suggestion in a glamorous ticket:
Upgrading to the latest version of node did indeed resolve my issue.
The text was updated successfully, but these errors were encountered: