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) {
11 app.use(function (req, res) {
12 res.json(req.is('application/json'))
17 .type('application/json')
19 .expect(200, '"application/json"', done)
22 it('should return false when not matching', function (done) {
25 app.use(function (req, res) {
26 res.json(req.is('image/jpeg'))
31 .type('application/json')
33 .expect(200, 'false', done)
36 it('should ignore charset', function (done) {
39 app.use(function (req, res) {
40 res.json(req.is('application/json'))
45 .type('application/json; charset=UTF-8')
47 .expect(200, '"application/json"', done)
51 describe('when content-type is not present', function(){
52 it('should return false', function (done) {
55 app.use(function (req, res) {
56 res.json(req.is('application/json'))
62 .expect(200, 'false', done)
66 describe('when given an extension', function(){
67 it('should lookup the mime type', function (done) {
70 app.use(function (req, res) {
71 res.json(req.is('json'))
76 .type('application/json')
78 .expect(200, '"json"', done)
82 describe('when given */subtype', function(){
83 it('should return the full type when matching', function (done) {
86 app.use(function (req, res) {
87 res.json(req.is('*/json'))
92 .type('application/json')
94 .expect(200, '"application/json"', done)
97 it('should return false when not matching', function (done) {
100 app.use(function (req, res) {
101 res.json(req.is('*/html'))
106 .type('application/json')
108 .expect(200, 'false', done)
111 it('should ignore charset', function (done) {
114 app.use(function (req, res) {
115 res.json(req.is('*/json'))
120 .type('application/json; charset=UTF-8')
122 .expect(200, '"application/json"', done)
126 describe('when given type/*', function(){
127 it('should return the full type when matching', function (done) {
130 app.use(function (req, res) {
131 res.json(req.is('application/*'))
136 .type('application/json')
138 .expect(200, '"application/json"', done)
141 it('should return false when not matching', function (done) {
144 app.use(function (req, res) {
145 res.json(req.is('text/*'))
150 .type('application/json')
152 .expect(200, 'false', done)
155 it('should ignore charset', function (done) {
158 app.use(function (req, res) {
159 res.json(req.is('application/*'))
164 .type('application/json; charset=UTF-8')
166 .expect(200, '"application/json"', done)