2 var express = require('..')
3 var request = require('supertest')
5 describe('req.is()', function () {
6 describe('when given a mime type', function () {
7 it('should return the type when matching', function (done) {
10 app.use(function (req, res) {
11 res.json(req.is('application/json'))
16 .type('application/json')
18 .expect(200, '"application/json"', done)
21 it('should return false when not matching', function (done) {
24 app.use(function (req, res) {
25 res.json(req.is('image/jpeg'))
30 .type('application/json')
32 .expect(200, 'false', done)
35 it('should ignore charset', function (done) {
38 app.use(function (req, res) {
39 res.json(req.is('application/json'))
44 .type('application/json; charset=UTF-8')
46 .expect(200, '"application/json"', done)
50 describe('when content-type is not present', function(){
51 it('should return false', function (done) {
54 app.use(function (req, res) {
55 res.json(req.is('application/json'))
61 .expect(200, 'false', done)
65 describe('when given an extension', function(){
66 it('should lookup the mime type', function (done) {
69 app.use(function (req, res) {
70 res.json(req.is('json'))
75 .type('application/json')
77 .expect(200, '"json"', done)
81 describe('when given */subtype', function(){
82 it('should return the full type when matching', function (done) {
85 app.use(function (req, res) {
86 res.json(req.is('*/json'))
91 .type('application/json')
93 .expect(200, '"application/json"', done)
96 it('should return false when not matching', function (done) {
99 app.use(function (req, res) {
100 res.json(req.is('*/html'))
105 .type('application/json')
107 .expect(200, 'false', done)
110 it('should ignore charset', function (done) {
113 app.use(function (req, res) {
114 res.json(req.is('*/json'))
119 .type('application/json; charset=UTF-8')
121 .expect(200, '"application/json"', done)
125 describe('when given type/*', function(){
126 it('should return the full type when matching', function (done) {
129 app.use(function (req, res) {
130 res.json(req.is('application/*'))
135 .type('application/json')
137 .expect(200, '"application/json"', done)
140 it('should return false when not matching', function (done) {
143 app.use(function (req, res) {
144 res.json(req.is('text/*'))
149 .type('application/json')
151 .expect(200, 'false', done)
154 it('should ignore charset', function (done) {
157 app.use(function (req, res) {
158 res.json(req.is('application/*'))
163 .type('application/json; charset=UTF-8')
165 .expect(200, '"application/json"', done)