-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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: Cannot read property 'Object.<anonymous>' of null #4710
Comments
I've found similar errors in other places: https://www.google.com/search?q=jest+Cannot+read+property+%27Object.%3Canonymous%3E%27+of+null&rlz=1C5CHFA_enUS703US703&oq=jest+Cannot+read+property+%27Object.%3Canonymous%3E%27+of+null&aqs=chrome..69i57j69i60l3j0l2.931j0j4&sourceid=chrome&ie=UTF-8 but have not found any posted resolution. If anyone is aware of a resolution please link and I'll close. |
I am getting the same error on 20.0.4 and can't find a way to shake the error. The tests were passing before I did a yarn install. |
If I switch my test environment from node to the default jsdom I get the following error instead
|
Can anyone provide a reproduction? I've come across this myself, but I can't seem to reproduce it now. A repro will go a long way towards helping us come up with a fix |
After fixing the error within one of the my projects I think I've got a theory as to why the error appears. Just to make sure it wasn't my machine I ran tests in an isolated jenkins job. The exact same error appeared. This ruled out that it was something specific with my laptop. From there I started to replicate tests manually and found that jest claimed that tests were passing when the functions and endpoints were actually error'ing out. This lead me to fixing bugs in my code that were producing 500 errors on endpoints and undefined errors in functions. After I fixed all the errors in my code the tests were passing completely fine. This leads me to believe that jest falls over when it encounters an error with an asynchronous test. I'll try and create a reproduction sometime soon but I'm not sure when I'll have time outside of work. |
What I observed was that the error came up after not awaiting an asynchronous operation. My theory was is that the cleanup ( I'm unable to reproduce, though... |
I haven't been able to confirm anything more on my side about what causes it, but the async stuff sounds like it's on the right track to me. It's happening in one of my repos where I'm testing real async functions (not mocks) and using Our CI (CircleCI) is running fine, so I wonder if this is in some way related to the watch mode. |
@jtulk, I've never used watch mode and I've also never used any clean up methods. I was using nothing but describe and it functions. The tests that were failing (but not showing as failed) were async tests that use supertest to hit endpoints. |
@silverlight513 did you return the result from supertest? |
Nope, the result doesn't serialize as far as I'm aware. I'd just call expect and finally the done function in the |
Ah, you called I meant that test('some stuff', () => {
return supertest(app)
.get('/')
.expect(200);
}) You don't need the |
Yeah, I just preferred using the done method as I had a problem in the past returning promises with async tests. Might have been back when I was using mocha but it's just become a habit. I assumed you meant this it('will respond with a success', done => {
supertest(app)
.get('/')
.then(res => {
expect(res.statusCode).toBe(200);
done();
return res;
});
}); |
@SimenB Deeper digging is making me think this is actually related to #2605 for me. As far as I can tell the error is thrown when using the New Relic node library: https://github.com/newrelic/node-newrelic |
I'm not so sure, the only modules I was using were supertest, superagent and express when I was running into the errors. I think the problem we've been experiencing is probably something to do with how jest handles async bugs in code. Some of bugs those bugs could come from other modules like node-newrelic and iconv-lite. Even if it does come down to purely an issue with other modules, Jest shouldn't show an unhelpful error and should try and send a meaningful error message. |
I think the issue is that we return Can send a PR for what I think will be a better error, but it would be great if we could get a reproduction to test it on |
I had this very issue, but it was sporadic. It was caused by opbeat, but I think it also had someting to do with creating a global.window object in my setup test file. Removing opbeat has fixed the issue for me. :| |
It's been broken consistently in my circle CI (jest running inside docker container with node:8.9.0 image, also tested with node:8.9.1 same error). The test run without a hitch in my local machine (even with the same setup as circle CI i.e. run in docker and node:8.9.0). But since it's always errored in the CI, I think I can test something in case anyone has any suggestion. Here's the log from jest:
Seems like coming from webpack there. update: After some tests I figure out that I can replicate the error in my local machine by running jest with I only have
and jest only error if it's running all tests at once, it wont error when running with any combination of two folders, or if it's only one of them e.g. For workaround I separate the tests into two jest calls: |
This will fail in Jest 22 because we clean up the contexts more aggressively. This error normally happens when you are scheduling async work after the test run for a file has already been completed. |
For others that find this issue, it can be caused by running an |
For the Animated problem, Can add this to your test file
|
Using |
I've opened up a PR trying to give a better error in this situation: #5888 |
Ah I overlooked... |
Change react-test-renderer to e.g. enzyme |
For people getting this, please try the Jest 23 beta ( |
@SimenB that error message helps a lot - thanks! |
None of the above fixes worked for me. While certainly not ideal, a simple workaround is adding |
In my case this issue was caused by the For anyone still in need for a fix for this, see this comment on how to mock the TextInput. |
hi @hnrchrdl, however I got an issue when I implemented the quickfix. The testcase seems like never ended. Is this also happened to you? What did you put on the |
Thanks a lot |
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. |
Trying to run Jest tests after upgrading.
Do you want to request a feature or report a bug?
Report a bug.
What is the current behavior?
yarn test
fails at runningscripts/test.js
(included). Throws primarily when trying to run all the tests, runningyarn watch
and only testing changed files has not reproduced the errors.If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can
yarn install
andyarn test
.What is the expected behavior?
Should run tests without crashing.
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
EDIT
Works finefails w/ Jest 20.0.4Fails on 21.2.1
scripts/test.js
Package.json
The text was updated successfully, but these errors were encountered: