Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions test/res.type.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ describe('res', function(){
.expect('Content-Type', 'application/vnd.amazon.ebook', done);
})

it('should set the Content-Type with type/subtype and parameters', function(done){
var app = express();

app.use(function(req, res){
res.type('text/html; charset=utf-8')
.end('<p>hello</p>');
});

request(app)
.get('/')
.expect('Content-Type', 'text/html; charset=utf-8', done);
})

describe('edge cases', function(){
it('should handle empty string gracefully', function(done){
var app = express();
Expand Down Expand Up @@ -110,6 +123,62 @@ describe('res', function(){
})
})
})

describe('.contentType(str)', function(){
it('should set the Content-Type based on a filename', function(done){
var app = express();

app.use(function(req, res){
res.contentType('foo.js').end('var name = "tj";');
});

request(app)
.get('/')
.expect('Content-Type', 'text/javascript; charset=utf-8')
.end(done)
})

it('should set the Content-Type with type/subtype', function(done){
var app = express();

app.use(function(req, res){
res.contentType('application/vnd.amazon.ebook')
.end('var name = "tj";');
});

request(app)
.get('/')
.expect('Content-Type', 'application/vnd.amazon.ebook', done);
})

it('should set the Content-Type with type/subtype and parameters', function(done){
var app = express();

app.use(function(req, res){
res.contentType('text/html; charset=utf-8')
.end('<p>hello</p>');
});

request(app)
.get('/')
.expect('Content-Type', 'text/html; charset=utf-8', done);
})

describe('edge cases', function(){
it('should handle empty string gracefully', function(done){
var app = express();

app.use(function(req, res){
res.contentType('').end('test');
});

request(app)
.get('/')
.expect('Content-Type', 'application/octet-stream')
.end(done);
})
})
})
})