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
69 lines
1.9 KiB
JavaScript
69 lines
1.9 KiB
JavaScript
|
|
'use strict';
|
|
|
|
const context = require('../helpers/context');
|
|
const assert = require('assert');
|
|
|
|
describe('ctx.type=', () => {
|
|
describe('with a mime', () => {
|
|
it('should set the Content-Type', () => {
|
|
const ctx = context();
|
|
ctx.type = 'text/plain';
|
|
ctx.type.should.equal('text/plain');
|
|
ctx.response.header['content-type'].should.equal('text/plain; charset=utf-8');
|
|
});
|
|
});
|
|
|
|
describe('with an extension', () => {
|
|
it('should lookup the mime', () => {
|
|
const ctx = context();
|
|
ctx.type = 'json';
|
|
ctx.type.should.equal('application/json');
|
|
ctx.response.header['content-type'].should.equal('application/json; charset=utf-8');
|
|
});
|
|
});
|
|
|
|
describe('without a charset', () => {
|
|
it('should default the charset', () => {
|
|
const ctx = context();
|
|
ctx.type = 'text/html';
|
|
ctx.type.should.equal('text/html');
|
|
ctx.response.header['content-type'].should.equal('text/html; charset=utf-8');
|
|
});
|
|
});
|
|
|
|
describe('with a charset', () => {
|
|
it('should not default the charset', () => {
|
|
const ctx = context();
|
|
ctx.type = 'text/html; charset=foo';
|
|
ctx.type.should.equal('text/html');
|
|
ctx.response.header['content-type'].should.equal('text/html; charset=foo');
|
|
});
|
|
});
|
|
|
|
describe('with an unknown extension', () => {
|
|
it('should not set a content-type', () => {
|
|
const ctx = context();
|
|
ctx.type = 'asdf';
|
|
assert(!ctx.type);
|
|
assert(!ctx.response.header['content-type']);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('ctx.type', () => {
|
|
describe('with no Content-Type', () => {
|
|
it('should return ""', () => {
|
|
const ctx = context();
|
|
assert(!ctx.type);
|
|
});
|
|
});
|
|
|
|
describe('with a Content-Type', () => {
|
|
it('should return the mime', () => {
|
|
const ctx = context();
|
|
ctx.type = 'json';
|
|
ctx.type.should.equal('application/json');
|
|
});
|
|
});
|
|
});
|