req.is.js
This file
Path
test/req.is.js
103 lines · 2.1 KiB · JavaScript
Last changed by
refactor req.is and req.accepts*Jonathan Ongbefore adoptioncec0c06
History of this fileTake it
The walk stopped after 200 commits: lines older than 66d9a4a point at it.
Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption66d9a4a
lines 1–6why, one step back12var express = require('../')3 , request = require('./support/http');45function req(ct) {6 var req = {refactor req.is and req.accepts*Jonathan Ongbefore adoptioncec0c06
lines 7–11why, one step back7 headers: {8 'content-type': ct,9 'transfer-encoding': 'chunked'10 },11 __proto__: express.requestMerge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption66d9a4a
lines 12–20why, one step back12 };1314 return req;15}1617describe('req.is()', function(){18 it('should ignore charset', function(){19 req('application/json; charset=utf-8')20 .is('json')refactor req.is and req.accepts*Jonathan Ongbefore adoptioncec0c06
line 21why, one step back21 .should.equal('json');Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption66d9a4a
lines 22–35why, one step back22 })2324 describe('when content-type is not present', function(){25 it('should return false', function(){26 req('')27 .is('json')28 .should.be.false;29 })30 })3132 describe('when given an extension', function(){33 it('should lookup the mime type', function(){34 req('application/json')35 .is('json')refactor req.is and req.accepts*Jonathan Ongbefore adoptioncec0c06
line 36why, one step back36 .should.equal('json');Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption66d9a4a
lines 37–47why, one step back3738 req('text/html')39 .is('json')40 .should.be.false;41 })42 })4344 describe('when given a mime type', function(){45 it('should match', function(){46 req('application/json')47 .is('application/json')refactor req.is and req.accepts*Jonathan Ongbefore adoptioncec0c06
line 48why, one step back48 .should.equal('application/json');Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption66d9a4a
lines 49–59why, one step back4950 req('image/jpeg')51 .is('application/json')52 .should.be.false;53 })54 })5556 describe('when given */subtype', function(){57 it('should match', function(){58 req('application/json')59 .is('*/json')refactor req.is and req.accepts*Jonathan Ongbefore adoptioncec0c06
line 60why, one step back60 .should.equal('application/json');Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption66d9a4a
lines 61–70why, one step back6162 req('image/jpeg')63 .is('*/json')64 .should.be.false;65 })6667 describe('with a charset', function(){68 it('should match', function(){69 req('text/html; charset=utf-8')70 .is('*/html')refactor req.is and req.accepts*Jonathan Ongbefore adoptioncec0c06
line 71why, one step back71 .should.equal('text/html');Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption66d9a4a
lines 72–83why, one step back7273 req('text/plain; charset=utf-8')74 .is('*/html')75 .should.be.false;76 })77 })78 })7980 describe('when given type/*', function(){81 it('should match', function(){82 req('image/png')83 .is('image/*')refactor req.is and req.accepts*Jonathan Ongbefore adoptioncec0c06
line 84why, one step back84 .should.equal('image/png');Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption66d9a4a
lines 85–94why, one step back8586 req('text/html')87 .is('image/*')88 .should.be.false;89 })9091 describe('with a charset', function(){92 it('should match', function(){93 req('text/html; charset=utf-8')94 .is('text/*')refactor req.is and req.accepts*Jonathan Ongbefore adoptioncec0c06
line 95why, one step back95 .should.equal('text/html');Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption66d9a4a
lines 96–103why, one step back9697 req('something/html; charset=utf-8')98 .is('text/*')99 .should.be.false;100 })101 })102 })103})