Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than 2ac2509 point at it.

4.13.1Douglas Christopher Wilsonbefore adoption2ac2509

line 1why, one step back
1

tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7

lines 2–3why, one step back
2var express = require('..')
3var request = require('supertest')

4.13.1Douglas Christopher Wilsonbefore adoption2ac2509

line 4why, one step back
4

tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7

lines 5–8why, one step back
5describe('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 back
9

tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7

lines 10–12why, one step back
10 app.use(function (req, res) {
11 res.json(req.is('application/json'))12 })

4.13.1Douglas Christopher Wilsonbefore adoption2ac2509

line 13why, one step back
13

tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7

lines 14–47why, one step back
14 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 back
48 })
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 back
51 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 back
62 })
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 back
66 it('should lookup the mime type', function (done) {
67 var app = express()

4.13.1Douglas Christopher Wilsonbefore adoption2ac2509

line 68why, one step back
68

tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7

lines 69–77why, one step back
69 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 back
78 })
79 })80

tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7

lines 81–83why, one step back
81 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 back
84

tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7

lines 85–93why, one step back
85 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 back
94 })
95

tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7

lines 96–97why, one step back
96 it('should return false when not matching', function (done) {
97 var app = express()

4.13.1Douglas Christopher Wilsonbefore adoption2ac2509

line 98why, one step back
98

tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7

lines 99–107why, one step back
99 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 back
108 })
109

tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7

lines 110–111why, one step back
110 it('should ignore charset', function (done) {
111 var app = express()

4.13.1Douglas Christopher Wilsonbefore adoption2ac2509

line 112why, one step back
112

tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7

lines 113–114why, one step back
113 app.use(function (req, res) {
114 res.json(req.is('*/json'))

4.13.1Douglas Christopher Wilsonbefore adoption2ac2509

line 115why, one step back
115 })

tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7

lines 116–121why, one step back
116
117 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 back
122 })
123 })124125 describe('when given type/*', function(){

tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7

lines 126–127why, one step back
126 it('should return the full type when matching', function (done) {
127 var app = express()

4.13.1Douglas Christopher Wilsonbefore adoption2ac2509

line 128why, one step back
128

tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7

lines 129–137why, one step back
129 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 back
138 })
139

tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7

lines 140–141why, one step back
140 it('should return false when not matching', function (done) {
141 var app = express()

4.13.1Douglas Christopher Wilsonbefore adoption2ac2509

line 142why, one step back
142

tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7

lines 143–144why, one step back
143 app.use(function (req, res) {
144 res.json(req.is('text/*'))

4.13.1Douglas Christopher Wilsonbefore adoption2ac2509

line 145why, one step back
145 })

tests: update req.is tests to run through expressDouglas Christopher Wilsonbefore adoptioneb326d7

lines 146–165why, one step back
146
147 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 back
166 })
167 })168})