Skip to content
Myr

res.type.js

This file

Path

test/res.type.js

115 lines · 2.7 KiB · JavaScript

Last changed by

test: include edge case tests for `res.type()` (#7037)Ishita Singhbefore adoptionb4ab7d6

History of this file

Take it

The walk stopped after 200 commits: lines older than 2027b87 point at it.

fix(deps): cookie@0.7.0Josh Bukerbefore adoption2027b87

lines 1–44why, one step back
1'use strict'
23var express = require('../')4 , request = require('supertest');56describe('res', function(){7 describe('.type(str)', function(){8 it('should set the Content-Type based on a filename', function(done){9 var app = express();1011 app.use(function(req, res){12 res.type('foo.js').end('var name = "tj";');13 });1415 request(app)16 .get('/')17 .expect('Content-Type', 'text/javascript; charset=utf-8')18 .end(done)19 })2021 it('should default to application/octet-stream', function(done){22 var app = express();2324 app.use(function(req, res){25 res.type('rawr').end('var name = "tj";');26 });2728 request(app)29 .get('/')30 .expect('Content-Type', 'application/octet-stream', done);31 })3233 it('should set the Content-Type with type/subtype', function(done){34 var app = express();3536 app.use(function(req, res){37 res.type('application/vnd.amazon.ebook')38 .end('var name = "tj";');39 });4041 request(app)42 .get('/')43 .expect('Content-Type', 'application/vnd.amazon.ebook', done);44 })

test: include edge case tests for `res.type()` (#7037)Ishita Singhbefore adoptionb4ab7d6

lines 45–111why, one step back
45
46 describe('edge cases', function(){47 it('should handle empty string gracefully', function(done){48 var app = express();4950 app.use(function(req, res){51 res.type('').end('test');52 });5354 request(app)55 .get('/')56 .expect('Content-Type', 'application/octet-stream')57 .end(done);58 })5960 it('should handle file extension with dots', function(done){61 var app = express();6263 app.use(function(req, res){64 res.type('.json').end('{"test": true}');65 });6667 request(app)68 .get('/')69 .expect('Content-Type', 'application/json; charset=utf-8')70 .end(done);71 })7273 it('should handle multiple file extensions', function(done){74 var app = express();7576 app.use(function(req, res){77 res.type('file.tar.gz').end('compressed');78 });7980 request(app)81 .get('/')82 .expect('Content-Type', 'application/gzip')83 .end(done);84 })8586 it('should handle uppercase extensions', function(done){87 var app = express();8889 app.use(function(req, res){90 res.type('FILE.JSON').end('{"test": true}');91 });9293 request(app)94 .get('/')95 .expect('Content-Type', 'application/json; charset=utf-8')96 .end(done);97 })9899 it('should handle extension with special characters', function(done){100 var app = express();101102 app.use(function(req, res){103 res.type('file@test.json').end('{"test": true}');104 });105106 request(app)107 .get('/')108 .expect('Content-Type', 'application/json; charset=utf-8')109 .end(done);110 })111 })

fix(deps): cookie@0.7.0Josh Bukerbefore adoption2027b87

lines 112–113why, one step back
112 })
113})

test: include edge case tests for `res.type()` (#7037)Ishita Singhbefore adoptionb4ab7d6

lines 114–115why, one step back
114
115