forwardemail / forwardemail/supertest

When status code expectation fails, can't figure out which request failed

Open
#317 20 comments 20 reactions 0 assignees View on GitHub
need-help
Dominant language
JavaScript
Stars
14.4k
Forks
782
PR merge metrics
No merged PRs in 30d

Description

In my Mocha tests I use `before()` hooks to send a number of requests to create data required for the actual tests. When one of the requests fails I end up with `supertest`'s internal stack trace, which doesn't tell which request failed. The only indication of error is that one of the requests returned with unexpected status code.

Here's an example

``` javascript
var request = require('supertest');
var url = 'www.example.com';

request(url)
.get('/')
.expect(200)
.end(function(err) {
if (err) console.log(err.stack);
});

request(url)
.get('/test')
.expect(200)
.end(function(err) {
if (err) console.log(err.stack);
});
```

which gives the following stack trace:

```
$ node test.js
Error: expected 200 "OK", got 404 "Not Found"
at Test._assertStatus (/my/path/node_modules/supertest/lib/test.js:232:12)
at Test._assertFunction (/my/path/node_modules/supertest/lib/test.js:247:11)
at Test.assert (/my/path/node_modules/supertest/lib/test.js:148:18)
at assert (/my/path/node_modules/supertest/lib/test.js:127:12)
at /my/path/node_modules/supertest/lib/test.js:124:5
at Test.Request.callback (/my/path/node_modules/supertest/node_modules/superagent/lib/node/index.js:831:3)
at Stream. (/my/path/node_modules/supertest/node_modules/superagent/lib/node/index.js:1049:12)
at Stream.emit (events.js:117:20)
at Unzip. (/my/path/node_modules/supertest/node_modules/superagent/lib/node/utils.js:108:12)
at Unzip.emit (events.js:117:20)
```

Is this an expected behaviour or this is something I can try to fix?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.