koa-lite/test/response/vary.js
2017-05-11 11:30:32 +08:00

35 lines
921 B
JavaScript

'use strict';
const assert = require('assert');
const context = require('../helpers/context');
describe('ctx.vary(field)', () => {
describe('when Vary is not set', () => {
it('should set it', () => {
const ctx = context();
ctx.vary('Accept');
assert.equal(ctx.response.header.vary, 'Accept');
});
});
describe('when Vary is set', () => {
it('should append', () => {
const ctx = context();
ctx.vary('Accept');
ctx.vary('Accept-Encoding');
assert.equal(ctx.response.header.vary, 'Accept, Accept-Encoding');
});
});
describe('when Vary already contains the value', () => {
it('should not append', () => {
const ctx = context();
ctx.vary('Accept');
ctx.vary('Accept-Encoding');
ctx.vary('Accept');
ctx.vary('Accept-Encoding');
assert.equal(ctx.response.header.vary, 'Accept, Accept-Encoding');
});
});
});