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
51 lines
1.6 KiB
JavaScript
51 lines
1.6 KiB
JavaScript
|
|
'use strict';
|
|
|
|
const context = require('../helpers/context');
|
|
|
|
describe('ctx.acceptsCharsets()', () => {
|
|
describe('with no arguments', () => {
|
|
describe('when Accept-Charset is populated', () => {
|
|
it('should return accepted types', () => {
|
|
const ctx = context();
|
|
ctx.req.headers['accept-charset'] = 'utf-8, iso-8859-1;q=0.2, utf-7;q=0.5';
|
|
ctx.acceptsCharsets().should.eql(['utf-8', 'utf-7', 'iso-8859-1']);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('with multiple arguments', () => {
|
|
describe('when Accept-Charset is populated', () => {
|
|
describe('if any types match', () => {
|
|
it('should return the best fit', () => {
|
|
const ctx = context();
|
|
ctx.req.headers['accept-charset'] = 'utf-8, iso-8859-1;q=0.2, utf-7;q=0.5';
|
|
ctx.acceptsCharsets('utf-7', 'utf-8').should.equal('utf-8');
|
|
});
|
|
});
|
|
|
|
describe('if no types match', () => {
|
|
it('should return false', () => {
|
|
const ctx = context();
|
|
ctx.req.headers['accept-charset'] = 'utf-8, iso-8859-1;q=0.2, utf-7;q=0.5';
|
|
ctx.acceptsCharsets('utf-16').should.be.false;
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('when Accept-Charset is not populated', () => {
|
|
it('should return the first type', () => {
|
|
const ctx = context();
|
|
ctx.acceptsCharsets('utf-7', 'utf-8').should.equal('utf-7');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('with an array', () => {
|
|
it('should return the best fit', () => {
|
|
const ctx = context();
|
|
ctx.req.headers['accept-charset'] = 'utf-8, iso-8859-1;q=0.2, utf-7;q=0.5';
|
|
ctx.acceptsCharsets(['utf-7', 'utf-8']).should.equal('utf-8');
|
|
});
|
|
});
|
|
});
|