req.is.js
This file
Path
test/req.is.js
103 lines · 2.1 KiB · JavaScript
Last changed by
move setHeader charset patch to .setJonathan Ongbefore adoptionbad55f7
History of this fileTake it
The walk stopped after 200 commits: lines older than ac2cbef point at it.
Merge pull request #1899 from visionmedia/remove-configureRoman Shtylmanbefore adoptionac2cbef
lines 1–2why, one step back12var express = require('../')remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 3why, one step back3 , request = require('supertest');Merge pull request #1899 from visionmedia/remove-configureRoman Shtylmanbefore adoptionac2cbef
lines 4–18why, one step back45function req(ct) {6 var req = {7 headers: {8 'content-type': ct,9 'transfer-encoding': 'chunked'10 },11 __proto__: express.request12 };1314 return req;15}1617describe('req.is()', function(){18 it('should ignore charset', function(){move setHeader charset patch to .setJonathan Ongbefore adoptionbad55f7
line 19why, one step back19 req('application/json')Merge pull request #1899 from visionmedia/remove-configureRoman Shtylmanbefore adoptionac2cbef
lines 20–103why, one step back20 .is('json')21 .should.equal('json');22 })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')36 .should.equal('json');3738 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')48 .should.equal('application/json');4950 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')60 .should.equal('application/json');6162 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')71 .should.equal('text/html');7273 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/*')84 .should.equal('image/png');8586 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/*')95 .should.equal('text/html');9697 req('something/html; charset=utf-8')98 .is('text/*')99 .should.be.false;100 })101 })102 })103})