req.is.js
This file
Path
test/req.is.js
100 lines · 2.0 KiB · JavaScript
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than 8ac3e80 point at it.
Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption8ac3e80
lines 1–100why, one step back12var express = require('../')3 , request = require('./support/http');45function req(ct) {6 var req = {7 headers: { 'content-type': ct }8 , __proto__: express.request9 };1011 return req;12}1314describe('req.is()', function(){15 it('should ignore charset', function(){16 req('application/json; charset=utf-8')17 .is('json')18 .should.be.true;19 })2021 describe('when content-type is not present', function(){22 it('should return false', function(){23 req('')24 .is('json')25 .should.be.false;26 })27 })2829 describe('when given an extension', function(){30 it('should lookup the mime type', function(){31 req('application/json')32 .is('json')33 .should.be.true;3435 req('text/html')36 .is('json')37 .should.be.false;38 })39 })4041 describe('when given a mime type', function(){42 it('should match', function(){43 req('application/json')44 .is('application/json')45 .should.be.true;4647 req('image/jpeg')48 .is('application/json')49 .should.be.false;50 })51 })5253 describe('when given */subtype', function(){54 it('should match', function(){55 req('application/json')56 .is('*/json')57 .should.be.true;5859 req('image/jpeg')60 .is('*/json')61 .should.be.false;62 })6364 describe('with a charset', function(){65 it('should match', function(){66 req('text/html; charset=utf-8')67 .is('*/html')68 .should.be.true;6970 req('text/plain; charset=utf-8')71 .is('*/html')72 .should.be.false;73 })74 })75 })7677 describe('when given type/*', function(){78 it('should match', function(){79 req('image/png')80 .is('image/*')81 .should.be.true;8283 req('text/html')84 .is('image/*')85 .should.be.false;86 })8788 describe('with a charset', function(){89 it('should match', function(){90 req('text/html; charset=utf-8')91 .is('text/*')92 .should.be.true;9394 req('something/html; charset=utf-8')95 .is('text/*')96 .should.be.false;97 })98 })99 })100})