question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property 'status' of undefined

See original GitHub issue

When sending test request with expected status code and getting response with invalid content type (eg. header says application/json, but server sends xml/html), the Test.prototype._assertStatus fails while getting status from res (which is undefined).

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:50
  • Comments:40 (2 by maintainers)

github_iconTop GitHub Comments

10reactions
danday74commented, Oct 4, 2016

I got this error when testing over a secure connection. I fixed it by adding NODE_TLS_REJECT_UNAUTHORIZED=0 as an env var on the test run.

For those wondering why this happens, it can happen because ‘127.0.0.1’ is not listed as a valid IP in your certificate. The underlying error is … Hostname/IP doesn’t match certificate’s altnames: "IP: 127.0.0.1 is not in the cert’s list: " However, you will not see this error message - Just the spurious and much disliked …

Cannot read property ‘status’ of undefined

Hope this helps someone. God bless.

6reactions
01binarycommented, Oct 17, 2017

Just got this error, and my problem is that I forgot the slash in get path: supertest(server).get('favicon.ico') gets me…

TypeError: Cannot read property 'status' of undefined
at Test.Object.<anonymous>.Test._assertStatus (node_modules/supertest/lib/test.js:268:10)
      at Test.Object.<anonymous>.Test._assertFunction (node_modules/supertest/lib/test.js:286:11)
      at Test.Object.<anonymous>.Test.assert (node_modules/supertest/lib/test.js:175:18)
      at Server.assert (node_modules/supertest/lib/test.js:132:12)

putting the slash in, supertest(server).get('/favicon.ico') …the test works as expected.

I traced the issue down to logic that applies assertions. It’s supposed to early-exit with an error if there was an error, but something causes it to run the assertions anyway and it fails because response is undefined when there’s an error:

callback that performs assertions gets resError { Error: connect ECONNREFUSED 127.0.0.1:80
          at Object._errnoException (util.js:1041:11)
          at _exceptionWithHostPort (util.js:1064:20)
          at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1153:14)
        code: 'ECONNREFUSED',
        errno: 'ECONNREFUSED',
        syscall: 'connect',
        address: '127.0.0.1',
        port: 80,
        response: undefined } res undefined

Maybe it fails because the un-intended effect of forgetting the slash means that it will try to connect to “http://favicon.ico” which isn’t a server?

Either way it needs some logic hardened in Test.assert (or whatever runs through the array of assertions and applies them) and a friendly error message saying it Couldn't connect to http://favicon.ico:80 to run the tests instead of throwing some IP number out - there is no way to know what that means without reading the whole library.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read property 'status' of undefined in reactjs
The reason why you cant read data.status is that data is undefined. To get the data and the status, you need to return...
Read more >
Cannot Read Property of Undefined in JavaScript - Rollbar
What Causes TypeError: Cannot Read Property of Undefined ... Undefined means that a variable has been declared but has not been assigned a...
Read more >
TypeError: Cannot read property 'status' of undefined
I have performed the following steps within my Google Cloud Shell: npm i @codahq/packs-sdk -g.
Read more >
Cannot read property 'status' of undefined · Issue #352 - GitHub
When sending test request with expected status code and getting response with invalid content type (eg. header says application/json, ...
Read more >
TypeError: Cannot read property 'status' of undefined on Get
I'm getting the weird error and I don't know why. I'm just doing a get request, I'm doing another one in the same...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found