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.

Expect Status with `done()` isn't working

See original GitHub issue

.expect(404, done) doesn’t seem to be failing if the response is actually 200. Not sure if I’m doing something wrong, or if I’ve found a bug?

http://stackoverflow.com/questions/37729206/supertest-expect-not-asserting-status-codes-correctly

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
bradwbradwcommented, Nov 24, 2016

I’m running supertest 2.0.0 and copying the exact code pasted here: https://github.com/visionmedia/supertest/issues/345#issuecomment-229496425

Both tests pass, so it seems like a breaking change was introduced in 2.0.0, maybe i’m missing something in the docs, but i’m not sure what to do to test the status code

so to work around this i add an end function:

      .end(function (err, res) {
        err ? done.fail(err) : done();
      });
3reactions
rpadovanicommented, Jan 11, 2017

I have the same problem:

This doesn’t fail:

request(app)
				.get('/labels')
				.expect(202, [validLabel, anotherValidLabel], done);

while this fails:

request(app)
				.get('/labels')
				.expect(202, [validLabel, anotherValidLabel])
				.end(err => err ? done.fail(err) : done());
Read more comments on GitHub >

github_iconTop Results From Across the Web

Expect Status with `done()` isn't working · Issue #345 - GitHub
it('should handle an 404 response in expect callback', function (done) { request(app) .get('/doesntExist') .timeout(1) .expect(404, function ( ...
Read more >
node.js - Supertest Expect Not Asserting Status Codes Correctly
The line of code that isn't working is .expect(404, done) if I change this to be .expect(200, done) then the test doesn't fail....
Read more >
Expect - Jest
When you're writing tests, you often need to check that values meet certain conditions. expect gives you access to a number of "matchers" ......
Read more >
HTTP/1.1: Status Code Definitions
A client MUST be prepared to accept one or more 1xx status responses prior to a regular response, even if the client does...
Read more >
405 Method Not Allowed - HTTP - MDN Web Docs
The HyperText Transfer Protocol (HTTP) 405 Method Not Allowed response status code indicates that the server knows the request method, ...
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