docsify/test/unit/router-history-base.test.js
2020-10-25 23:05:16 -05:00

70 lines
2.0 KiB
JavaScript

const { History } = require('../../src/core/router/history/base');
class MockHistory extends History {
parse(path) {
return { path };
}
}
// Suite
// -----------------------------------------------------------------------------
describe('router/history/base', () => {
// Setup & Teardown
// ---------------------------------------------------------------------------
let history;
// resolvePath: true
// ---------------------------------------------------------------------------
describe('relativePath: true', () => {
// Setup & Teardown
// -------------------------------------------------------------------------
beforeEach(() => {
history = new MockHistory({ relativePath: true });
});
// Tests
// -------------------------------------------------------------------------
test('toURL', () => {
const url = history.toURL('guide.md', {}, '/zh-ch/');
expect(url).toEqual('/zh-ch/guide');
});
test('toURL with double dot', () => {
const url = history.toURL('../README.md', {}, '/zh-ch/');
expect(url).toEqual('/README');
});
test('toURL child path', () => {
const url = history.toURL('config/example.md', {}, '/zh-ch/');
expect(url).toEqual('/zh-ch/config/example');
});
test('toURL absolute path', () => {
const url = history.toURL('/README', {}, '/zh-ch/');
expect(url).toEqual('/README');
});
});
// resolvePath: false
// ---------------------------------------------------------------------------
describe('relativePath: false', () => {
// Setup & Teardown
// -------------------------------------------------------------------------
beforeEach(() => {
history = new MockHistory({ relativePath: false });
});
// Tests
// -------------------------------------------------------------------------
test('toURL', () => {
const url = history.toURL('README', {}, '/zh-ch/');
expect(url).toEqual('/README');
});
});
});