-
Notifications
You must be signed in to change notification settings - Fork 759
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
expect(!2xx) throws exception #556
Comments
A simple test case: it('should assert using promises', function (done) {
const app = express();
app.get('/', function (req, res) {
res.status(400).end();
});
request(app)
.get('/')
.expect(400)
.then(done)
.catch(done);
}); |
Updated: revert to v3.4.2. Everything back to normal. I have similar issue too. const request = require('supertest');
const express = require('express');
const app = express();
app.get('/user', function (req, res) {
res.status(400).send();
});
test('Should pass this test with status 400', async () => {
await request(app).get('/user').expect(400)
}) Expect the test to pass, but instead:
|
This is the same issue as #534, which was caused by upgrading superagent to v4.1.0. This previous issue was resolved at the time by downgrading superagent to v3.8.3. superagent has again been upgraded without a proper fix in place. |
async and promises are broken
|
same here. |
@gjohnson Do you have some time for fixing that? 🙏 |
same here |
Same here, I'm not sure if this change was intented, but a !2XX response shouldn't trigger a failure |
Worth following upstream: ladjs/superagent#1466 |
Thanks for reporting the issue. While we are waiting for a fix, we can use this technique to resolve it: it("should return status code 400", () => {
return request(app)
.get("/")
.catch(res => {
expect(res.status).toBe(400);
});
}); Or, with async/await: it("should return status code 400", async () => {
await request(app)
.get("/")
.catch(res => {
expect(res.status).toBe(400);
});
}); |
#558 merged, I close this issue. Thank you 🙏 |
I have migrated to the latest version of supertest (4.0.0), but all my tests that expect a status code different to 2xx fails.
Example:
Will throw an
Error: Not Found
exception.The text was updated successfully, but these errors were encountered: