koa-lite/test/request/path.js

33 lines
822 B
JavaScript
Raw Permalink Normal View History

'use strict';
2017-05-11 03:30:32 +00:00
const assert = require('assert');
const context = require('../helpers/context');
describe('ctx.path', () => {
it('should return the pathname', () => {
const ctx = context();
ctx.url = '/login?next=/dashboard';
2017-05-11 03:30:32 +00:00
assert.equal(ctx.path, '/login');
2015-10-12 20:36:41 +00:00
});
});
describe('ctx.path=', () => {
it('should set the pathname', () => {
const ctx = context();
ctx.url = '/login?next=/dashboard';
ctx.path = '/logout';
2017-05-11 03:30:32 +00:00
assert.equal(ctx.path, '/logout');
assert.equal(ctx.url, '/logout?next=/dashboard');
2015-10-12 20:36:41 +00:00
});
it('should change .url but not .originalUrl', () => {
const ctx = context({ url: '/login' });
ctx.path = '/logout';
2017-05-11 03:30:32 +00:00
assert.equal(ctx.url, '/logout');
assert.equal(ctx.originalUrl, '/login');
assert.equal(ctx.request.originalUrl, '/login');
2015-10-12 20:36:41 +00:00
});
});