.expect(201) passes when res.status == 400
See original GitHub issueSorry to create another ticket out of what may be ignorance but…
describe('POST /', function(){
it('should pass with good img_uri', function(done){
request(app)
.post('/')
.send({
img_uri: '/foo.png'
})
.expect(201)
.expect('Content-Type', /json/)
.expect( { ok: 1 } )
.end(function(err, res){
console.log( 'BODY: ' );
console.log( res.body );
console.log( res.status );
console.log( 'res.status == 201: '+ res.status == 201 );
done()
})
})
});
The output (in TAP format):
BODY:
{ ok: 0, msg: 'Missing parameters: img_uri' }
400
false
ok 1 POST / should pass with good img_uri
This seems to show that either the chained .expect() calls are behaving differently than in the examples, or that I failed to understand how they should work.
TIA Lee
Issue Analytics
- State:
- Created 11 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
expect(201) passes when res.status == 400 · Issue #11 - GitHub
Sorry to create another ticket out of what may be ignorance but... ... This seems to show that either the chained .expect() calls...
Read more >Why is NodeJS crashing when API returns 400 HTTP status ...
json(response); //if all is OK it will return 201, but if not 400 };. So I've tried catching the status code in addReservation...
Read more >A Complete Guide and List of HTTP Status Codes - Kinsta
These are error codes specifying that there's a fault with your browser and/or request. 400: “Bad Request.” The server can't return a response...
Read more >A testing guide for Express with request and response ...
To test an Express handler, it's useful to know how to successfully mock/stub the request and response objects. The following examp.
Read more >What are the Different types of Asserts in Postman? - Tools QA
Note: 201 is created and 202 is Accepted. Press send and see the response which will be pass if the status code is...
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
I happen to have the same problem, and found how to solve it simply.
Do as @mfrobben says,
expect(SOME_CODE, done)
when you don’t need complete access to the error and the response.When you need complete access to do custom stuff in the
end
callback, test the error as follows :I first tried without an
else
statement, but I got this error :Error: done() called multiple times
.I was getting this error but it turned out it was because I wasn’t separating my redirect/render code paths properly. I forgot to put a return after the redirect so it ended up redirecting then rendering on the same response object.