Skip to content
Myr

req.is.js

This file

Path

test/req.is.js

169 lines · 3.7 KiB · JavaScript

Last changed by

Not known.

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–169why, one step back
1'use strict'
23var express = require('..')4var request = require('supertest')56describe('req.is()', function () {7 describe('when given a mime type', function () {8 it('should return the type when matching', function (done) {9 var app = express()1011 app.use(function (req, res) {12 res.json(req.is('application/json'))13 })1415 request(app)16 .post('/')17 .type('application/json')18 .send('{}')19 .expect(200, '"application/json"', done)20 })2122 it('should return false when not matching', function (done) {23 var app = express()2425 app.use(function (req, res) {26 res.json(req.is('image/jpeg'))27 })2829 request(app)30 .post('/')31 .type('application/json')32 .send('{}')33 .expect(200, 'false', done)34 })3536 it('should ignore charset', function (done) {37 var app = express()3839 app.use(function (req, res) {40 res.json(req.is('application/json'))41 })4243 request(app)44 .post('/')45 .type('application/json; charset=UTF-8')46 .send('{}')47 .expect(200, '"application/json"', done)48 })49 })5051 describe('when content-type is not present', function(){52 it('should return false', function (done) {53 var app = express()5455 app.use(function (req, res) {56 res.json(req.is('application/json'))57 })5859 request(app)60 .post('/')61 .send('{}')62 .expect(200, 'false', done)63 })64 })6566 describe('when given an extension', function(){67 it('should lookup the mime type', function (done) {68 var app = express()6970 app.use(function (req, res) {71 res.json(req.is('json'))72 })7374 request(app)75 .post('/')76 .type('application/json')77 .send('{}')78 .expect(200, '"json"', done)79 })80 })8182 describe('when given */subtype', function(){83 it('should return the full type when matching', function (done) {84 var app = express()8586 app.use(function (req, res) {87 res.json(req.is('*/json'))88 })8990 request(app)91 .post('/')92 .type('application/json')93 .send('{}')94 .expect(200, '"application/json"', done)95 })9697 it('should return false when not matching', function (done) {98 var app = express()99100 app.use(function (req, res) {101 res.json(req.is('*/html'))102 })103104 request(app)105 .post('/')106 .type('application/json')107 .send('{}')108 .expect(200, 'false', done)109 })110111 it('should ignore charset', function (done) {112 var app = express()113114 app.use(function (req, res) {115 res.json(req.is('*/json'))116 })117118 request(app)119 .post('/')120 .type('application/json; charset=UTF-8')121 .send('{}')122 .expect(200, '"application/json"', done)123 })124 })125126 describe('when given type/*', function(){127 it('should return the full type when matching', function (done) {128 var app = express()129130 app.use(function (req, res) {131 res.json(req.is('application/*'))132 })133134 request(app)135 .post('/')136 .type('application/json')137 .send('{}')138 .expect(200, '"application/json"', done)139 })140141 it('should return false when not matching', function (done) {142 var app = express()143144 app.use(function (req, res) {145 res.json(req.is('text/*'))146 })147148 request(app)149 .post('/')150 .type('application/json')151 .send('{}')152 .expect(200, 'false', done)153 })154155 it('should ignore charset', function (done) {156 var app = express()157158 app.use(function (req, res) {159 res.json(req.is('application/*'))160 })161162 request(app)163 .post('/')164 .type('application/json; charset=UTF-8')165 .send('{}')166 .expect(200, '"application/json"', done)167 })168 })169})