Supertest fails on Content-Type
See original GitHub issueSupertest says the content-type is text/plain, but when I use Postman or Chrome devtools and check the network tab, it correctly shows the content-type as text/html.
describe('Core controller unit tests:', function() {
before(function(done) {
request = request('http://localhost:3001');
done();
});
describe('Loading the homepage', function() {
it('should return 200 from GET /', function(done) {
request
.get('/')
.expect('Content-Type', /html/)
.expect(200, done);
});
});
after(function(done) {
done();
});
});
Issue Analytics
- State:
- Created 9 years ago
- Reactions:3
- Comments:22 (3 by maintainers)
Top Results From Across the Web
Supertest fails on Content-Type · Issue #187 - GitHub
Supertest says the content-type is text/plain, but when I use Postman or Chrome devtools and check the network tab, it correctly shows the...
Read more >Why my Supertest test that should be failing is passing?
The problem is that your test is asynchronous, but your code is synchronous. Specifically, the done() line is always called.
Read more >Testing an Express App With Supertest and Jest
In this article, we're going to look at how to use TDD to test an express API using the supertest and jest frameworks....
Read more >Testing Express Api with Jest and Supertest
First we have to pass our app.js module in to be able to make a request, then we define the route, what is...
Read more >Supertest: How to Test APIs Like a Pro - Testim Blog
SuperTest is a Node.js testing library for HTTP APIs. ... You can try to expect() something different to see how the test fails....
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
+1 always getting “text/html; charset=utf-8” no matter what I do.
Had this error in an older project using https://www.npmjs.com/package/express-force-https … not a very popular package, but it will cause Express to always return 302 with html/text when using Supertest. With the tests expecting Content-Type of /json/ of course. Easy fix was to not use this package in test env. Commenting here in the off chance it saves someone else several hours of googling and debugging.