4b1a1da652
closes #553 Update test: application -> use() should throw if not a function Fix lint Use arrow function Refactor test using arrow function Remove non mandatory brackets fix for merge Fix: missing refactor after merge Use arrow function for old generator
86 lines
2.7 KiB
JavaScript
86 lines
2.7 KiB
JavaScript
|
|
'use strict';
|
|
|
|
const context = require('../helpers/context');
|
|
const assert = require('assert');
|
|
|
|
describe('response.is(type)', () => {
|
|
it('should ignore params', () => {
|
|
const res = context().response;
|
|
res.type = 'text/html; charset=utf-8';
|
|
|
|
res.is('text/*').should.equal('text/html');
|
|
});
|
|
|
|
describe('when no type is set', () => {
|
|
it('should return false', () => {
|
|
const res = context().response;
|
|
|
|
assert(false === res.is());
|
|
assert(false === res.is('html'));
|
|
});
|
|
});
|
|
|
|
describe('when given no types', () => {
|
|
it('should return the type', () => {
|
|
const res = context().response;
|
|
res.type = 'text/html; charset=utf-8';
|
|
|
|
res.is().should.equal('text/html');
|
|
});
|
|
});
|
|
|
|
describe('given one type', () => {
|
|
it('should return the type or false', () => {
|
|
const res = context().response;
|
|
res.type = 'image/png';
|
|
|
|
res.is('png').should.equal('png');
|
|
res.is('.png').should.equal('.png');
|
|
res.is('image/png').should.equal('image/png');
|
|
res.is('image/*').should.equal('image/png');
|
|
res.is('*/png').should.equal('image/png');
|
|
|
|
res.is('jpeg').should.be.false;
|
|
res.is('.jpeg').should.be.false;
|
|
res.is('image/jpeg').should.be.false;
|
|
res.is('text/*').should.be.false;
|
|
res.is('*/jpeg').should.be.false;
|
|
});
|
|
});
|
|
|
|
describe('given multiple types', () => {
|
|
it('should return the first match or false', () => {
|
|
const res = context().response;
|
|
res.type = 'image/png';
|
|
|
|
res.is('png').should.equal('png');
|
|
res.is('.png').should.equal('.png');
|
|
res.is('text/*', 'image/*').should.equal('image/png');
|
|
res.is('image/*', 'text/*').should.equal('image/png');
|
|
res.is('image/*', 'image/png').should.equal('image/png');
|
|
res.is('image/png', 'image/*').should.equal('image/png');
|
|
|
|
res.is(['text/*', 'image/*']).should.equal('image/png');
|
|
res.is(['image/*', 'text/*']).should.equal('image/png');
|
|
res.is(['image/*', 'image/png']).should.equal('image/png');
|
|
res.is(['image/png', 'image/*']).should.equal('image/png');
|
|
|
|
res.is('jpeg').should.be.false;
|
|
res.is('.jpeg').should.be.false;
|
|
res.is('text/*', 'application/*').should.be.false;
|
|
res.is('text/html', 'text/plain', 'application/json; charset=utf-8').should.be.false;
|
|
});
|
|
});
|
|
|
|
describe('when Content-Type: application/x-www-form-urlencoded', () => {
|
|
it('should match "urlencoded"', () => {
|
|
const res = context().response;
|
|
res.type = 'application/x-www-form-urlencoded';
|
|
|
|
res.is('urlencoded').should.equal('urlencoded');
|
|
res.is('json', 'urlencoded').should.equal('urlencoded');
|
|
res.is('urlencoded', 'json').should.equal('urlencoded');
|
|
});
|
|
});
|
|
});
|