expect(!2xx) throws exception
See original GitHub issueI 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:
const request = require('supertest');
const express = require('express');
const app = express();
app.get('/user', function (req, res) {
res.status(404).end();
});
(async () => {
await request(app)
.get('/user')
.expect(404)
.send({ hello: 'hi' })
})();
Will throw an Error: Not Found
exception.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:22
- Comments:12 (3 by maintainers)
Top Results From Across the Web
expect(!2xx) throws exception · Issue #556 · ladjs/supertest
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....
Read more >TestRestTemplate throws exception for 4xx status codes
The problem I'm encountering is that because my REST call expects a complex JSON, for blocked calls the tests fail because TestRestTemplate is ......
Read more >Response validation - Ktor
Use the expectSuccess property to throw exceptions for non-2xx responses. Add stricter validation of 2xx responses. Customize validation of non-2xx ...
Read more >Java Examples & Tutorials of StatusResultMatchers.is (org ...
public void testMatcher() throws Exception { this.mockMvc.perform(get("/badRequest")).andExpect(status().is(equalTo(400)));
Read more >Spring Web Client Exception Handling | by David - Medium
Usually when handling HTTP exceptions, you focus on two different types; one is when the request is successful but the resource returns a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for reporting the issue. While we are waiting for a fix, we can use this technique to resolve it:
Or, with async/await:
@rimiti looking at this right now - these reports are much clearer @midrissi.