mirror of
https://github.com/zebrajr/express.git
synced 2025-12-06 12:19:51 +01:00
note that application/json no longer adds charset=utf-8. could be a regression. closes #1952 See also: https://github.com/broofa/node-mime/issues/86
104 lines
2.1 KiB
JavaScript
104 lines
2.1 KiB
JavaScript
|
|
var express = require('../')
|
|
, request = require('supertest');
|
|
|
|
function req(ct) {
|
|
var req = {
|
|
headers: {
|
|
'content-type': ct,
|
|
'transfer-encoding': 'chunked'
|
|
},
|
|
__proto__: express.request
|
|
};
|
|
|
|
return req;
|
|
}
|
|
|
|
describe('req.is()', function(){
|
|
it('should ignore charset', function(){
|
|
req('application/json')
|
|
.is('json')
|
|
.should.equal('json');
|
|
})
|
|
|
|
describe('when content-type is not present', function(){
|
|
it('should return false', function(){
|
|
req('')
|
|
.is('json')
|
|
.should.be.false;
|
|
})
|
|
})
|
|
|
|
describe('when given an extension', function(){
|
|
it('should lookup the mime type', function(){
|
|
req('application/json')
|
|
.is('json')
|
|
.should.equal('json');
|
|
|
|
req('text/html')
|
|
.is('json')
|
|
.should.be.false;
|
|
})
|
|
})
|
|
|
|
describe('when given a mime type', function(){
|
|
it('should match', function(){
|
|
req('application/json')
|
|
.is('application/json')
|
|
.should.equal('application/json');
|
|
|
|
req('image/jpeg')
|
|
.is('application/json')
|
|
.should.be.false;
|
|
})
|
|
})
|
|
|
|
describe('when given */subtype', function(){
|
|
it('should match', function(){
|
|
req('application/json')
|
|
.is('*/json')
|
|
.should.equal('application/json');
|
|
|
|
req('image/jpeg')
|
|
.is('*/json')
|
|
.should.be.false;
|
|
})
|
|
|
|
describe('with a charset', function(){
|
|
it('should match', function(){
|
|
req('text/html; charset=utf-8')
|
|
.is('*/html')
|
|
.should.equal('text/html');
|
|
|
|
req('text/plain; charset=utf-8')
|
|
.is('*/html')
|
|
.should.be.false;
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('when given type/*', function(){
|
|
it('should match', function(){
|
|
req('image/png')
|
|
.is('image/*')
|
|
.should.equal('image/png');
|
|
|
|
req('text/html')
|
|
.is('image/*')
|
|
.should.be.false;
|
|
})
|
|
|
|
describe('with a charset', function(){
|
|
it('should match', function(){
|
|
req('text/html; charset=utf-8')
|
|
.is('text/*')
|
|
.should.equal('text/html');
|
|
|
|
req('something/html; charset=utf-8')
|
|
.is('text/*')
|
|
.should.be.false;
|
|
})
|
|
})
|
|
})
|
|
})
|