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.

Supertest should report custom error messages

See original GitHub issue

At the moment when the status message does not match the expectations we get an error message like:

"expected 200 "OK", got 500 "Internal server error"

It would be helpful to display a server custom error message if any, as defined by:

res.send(500, { error: 'something blew up' });

would display:

"expected 200 "OK", got 500 "something blew up"

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Reactions:10
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

16reactions
reggicommented, Aug 31, 2015

I’m feeling the same way. Its really non-descriptive to have the standard status code error. However this is a pretty simple work around when trying to the match status code:

request(app)
.get(path)
.expect(function (res) {
  var expectedCode = 302
  var result = res.statusCode + " " + JSON.stringify(res.text)
  var expected = expectedCode + " " + JSON.stringify(res.text)
  assert.equal(result, expected)
})
9reactions
malthejorgensencommented, Feb 24, 2015

👍 Please reopen

I think this should be a part of supertest. Fixing a bug in the code, where the test simply states the error was 500 Internal Server Error is difficult. And it’s extra frustrating if you know your code is actually returning a meaningful error message.

Others seem to feel the same way: https://github.com/frenchie4111/supertest/commit/850d5d893d313f4515a581c16cb173a74fd7b4f8 (supertest fork)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Supertest should report custom error messages #95 - GitHub
I think this should be a part of supertest. Fixing a bug in the code, where the test simply states the error was...
Read more >
Is it possible to add information to the error message in supertest
I'd just like a little more information. For example: it('should successfully post my data and return a valid JSON', function( ...
Read more >
Testing Error Handling in node.js | by Lars Trieloff
Here are four techniques I use to achieve consistently high test coverage and ensure my programs are not just working as expected, but...
Read more >
How to use patch function in SuperTest - Javascript - Tabnine
Best JavaScript code snippets using supertest. ... it('should report error "User does not exist" when user does not exists', () => { return...
Read more >
How To Implement Custom Error Responses in Express - Auth0
This is a brilliant idea to provide the caller with pathways to solutions and not just report error messages. Also, if something changes,...
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