req.is.js
This file
Path
test/req.is.js
168 lines · 3.7 KiB · JavaScript
Last changed by
tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7
History of this fileTake it
The walk stopped after 200 commits: lines older than 2ac2509 point at it.
4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
line 1why, one step back1tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7
lines 2–3why, one step back2var express = require('..')3var request = require('supertest')4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
line 4why, one step back4tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7
lines 5–8why, one step back5describe('req.is()', function () {6 describe('when given a mime type', function () {7 it('should return the type when matching', function (done) {8 var app = express()4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
line 9why, one step back9tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7
lines 10–12why, one step back10 app.use(function (req, res) {11 res.json(req.is('application/json'))12 })4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
line 13why, one step back13tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7
lines 14–47why, one step back14 request(app)15 .post('/')16 .type('application/json')17 .send('{}')18 .expect(200, '"application/json"', done)19 })2021 it('should return false when not matching', function (done) {22 var app = express()2324 app.use(function (req, res) {25 res.json(req.is('image/jpeg'))26 })2728 request(app)29 .post('/')30 .type('application/json')31 .send('{}')32 .expect(200, 'false', done)33 })3435 it('should ignore charset', function (done) {36 var app = express()3738 app.use(function (req, res) {39 res.json(req.is('application/json'))40 })4142 request(app)43 .post('/')44 .type('application/json; charset=UTF-8')45 .send('{}')46 .expect(200, '"application/json"', done)47 })4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 48–50why, one step back48 })4950 describe('when content-type is not present', function(){tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7
lines 51–61why, one step back51 it('should return false', function (done) {52 var app = express()5354 app.use(function (req, res) {55 res.json(req.is('application/json'))56 })5758 request(app)59 .post('/')60 .send('{}')61 .expect(200, 'false', done)4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 62–65why, one step back62 })63 })6465 describe('when given an extension', function(){tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7
lines 66–67why, one step back66 it('should lookup the mime type', function (done) {67 var app = express()4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
line 68why, one step back68tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7
lines 69–77why, one step back69 app.use(function (req, res) {70 res.json(req.is('json'))71 })7273 request(app)74 .post('/')75 .type('application/json')76 .send('{}')77 .expect(200, '"json"', done)4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 78–80why, one step back78 })79 })80tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7
lines 81–83why, one step back81 describe('when given */subtype', function(){82 it('should return the full type when matching', function (done) {83 var app = express()4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
line 84why, one step back84tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7
lines 85–93why, one step back85 app.use(function (req, res) {86 res.json(req.is('*/json'))87 })8889 request(app)90 .post('/')91 .type('application/json')92 .send('{}')93 .expect(200, '"application/json"', done)4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 94–95why, one step back94 })95tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7
lines 96–97why, one step back96 it('should return false when not matching', function (done) {97 var app = express()4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
line 98why, one step back98tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7
lines 99–107why, one step back99 app.use(function (req, res) {100 res.json(req.is('*/html'))101 })102103 request(app)104 .post('/')105 .type('application/json')106 .send('{}')107 .expect(200, 'false', done)4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 108–109why, one step back108 })109tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7
lines 110–111why, one step back110 it('should ignore charset', function (done) {111 var app = express()4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
line 112why, one step back112tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7
lines 113–114why, one step back113 app.use(function (req, res) {114 res.json(req.is('*/json'))4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
line 115why, one step back115 })tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7
lines 116–121why, one step back116117 request(app)118 .post('/')119 .type('application/json; charset=UTF-8')120 .send('{}')121 .expect(200, '"application/json"', done)4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 122–125why, one step back122 })123 })124125 describe('when given type/*', function(){tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7
lines 126–127why, one step back126 it('should return the full type when matching', function (done) {127 var app = express()4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
line 128why, one step back128tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7
lines 129–137why, one step back129 app.use(function (req, res) {130 res.json(req.is('application/*'))131 })132133 request(app)134 .post('/')135 .type('application/json')136 .send('{}')137 .expect(200, '"application/json"', done)4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 138–139why, one step back138 })139tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7
lines 140–141why, one step back140 it('should return false when not matching', function (done) {141 var app = express()4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
line 142why, one step back142tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7
lines 143–144why, one step back143 app.use(function (req, res) {144 res.json(req.is('text/*'))4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
line 145why, one step back145 })tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7
lines 146–165why, one step back146147 request(app)148 .post('/')149 .type('application/json')150 .send('{}')151 .expect(200, 'false', done)152 })153154 it('should ignore charset', function (done) {155 var app = express()156157 app.use(function (req, res) {158 res.json(req.is('application/*'))159 })160161 request(app)162 .post('/')163 .type('application/json; charset=UTF-8')164 .send('{}')165 .expect(200, '"application/json"', done)4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 166–168why, one step back166 })167 })168})