fix(deps)!: mime-types@^3.0.0 (#5882)
[express.git] / test / req.is.js
blobc5904dd600af6ae3dff023cbb188227a2b9f8114
1 'use strict'
3 var express = require('..')
4 var request = require('supertest')
6 describe('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()
11 app.use(function (req, res) {
12 res.json(req.is('application/json'))
15 request(app)
16 .post('/')
17 .type('application/json')
18 .send('{}')
19 .expect(200, '"application/json"', done)
22 it('should return false when not matching', function (done) {
23 var app = express()
25 app.use(function (req, res) {
26 res.json(req.is('image/jpeg'))
29 request(app)
30 .post('/')
31 .type('application/json')
32 .send('{}')
33 .expect(200, 'false', done)
36 it('should ignore charset', function (done) {
37 var app = express()
39 app.use(function (req, res) {
40 res.json(req.is('application/json'))
43 request(app)
44 .post('/')
45 .type('application/json; charset=UTF-8')
46 .send('{}')
47 .expect(200, '"application/json"', done)
51 describe('when content-type is not present', function(){
52 it('should return false', function (done) {
53 var app = express()
55 app.use(function (req, res) {
56 res.json(req.is('application/json'))
59 request(app)
60 .post('/')
61 .send('{}')
62 .expect(200, 'false', done)
66 describe('when given an extension', function(){
67 it('should lookup the mime type', function (done) {
68 var app = express()
70 app.use(function (req, res) {
71 res.json(req.is('json'))
74 request(app)
75 .post('/')
76 .type('application/json')
77 .send('{}')
78 .expect(200, '"json"', done)
82 describe('when given */subtype', function(){
83 it('should return the full type when matching', function (done) {
84 var app = express()
86 app.use(function (req, res) {
87 res.json(req.is('*/json'))
90 request(app)
91 .post('/')
92 .type('application/json')
93 .send('{}')
94 .expect(200, '"application/json"', done)
97 it('should return false when not matching', function (done) {
98 var app = express()
100 app.use(function (req, res) {
101 res.json(req.is('*/html'))
104 request(app)
105 .post('/')
106 .type('application/json')
107 .send('{}')
108 .expect(200, 'false', done)
111 it('should ignore charset', function (done) {
112 var app = express()
114 app.use(function (req, res) {
115 res.json(req.is('*/json'))
118 request(app)
119 .post('/')
120 .type('application/json; charset=UTF-8')
121 .send('{}')
122 .expect(200, '"application/json"', done)
126 describe('when given type/*', function(){
127 it('should return the full type when matching', function (done) {
128 var app = express()
130 app.use(function (req, res) {
131 res.json(req.is('application/*'))
134 request(app)
135 .post('/')
136 .type('application/json')
137 .send('{}')
138 .expect(200, '"application/json"', done)
141 it('should return false when not matching', function (done) {
142 var app = express()
144 app.use(function (req, res) {
145 res.json(req.is('text/*'))
148 request(app)
149 .post('/')
150 .type('application/json')
151 .send('{}')
152 .expect(200, 'false', done)
155 it('should ignore charset', function (done) {
156 var app = express()
158 app.use(function (req, res) {
159 res.json(req.is('application/*'))
162 request(app)
163 .post('/')
164 .type('application/json; charset=UTF-8')
165 .send('{}')
166 .expect(200, '"application/json"', done)