mirror of
https://github.com/docsifyjs/docsify.git
synced 2025-12-08 19:55:52 +00:00
BREAKING: The new project layout might break in some tooling setups. We've added an exports field to `package.json` to specify where statements like `import ... from 'docsify'` will import from, and left the `main` and `unpkg` fields as-is for backwards compatibility with the global <script> import method. Most people who use a non-module `<script>` tag to import Docsify will not notice a difference. Anyone else who is importing Docsify into a specilized build setup using `import` statements has a chance of being broken, so we've marked this as BREAKING.
70 lines
2.0 KiB
JavaScript
70 lines
2.0 KiB
JavaScript
import { History } from '../../src/core/router/history/base.js';
|
|
|
|
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).toBe('/zh-ch/guide');
|
|
});
|
|
|
|
test('toURL with double dot', () => {
|
|
const url = history.toURL('../README.md', {}, '/zh-ch/');
|
|
|
|
expect(url).toBe('/README');
|
|
});
|
|
|
|
test('toURL child path', () => {
|
|
const url = history.toURL('config/example.md', {}, '/zh-ch/');
|
|
|
|
expect(url).toBe('/zh-ch/config/example');
|
|
});
|
|
|
|
test('toURL absolute path', () => {
|
|
const url = history.toURL('/README', {}, '/zh-ch/');
|
|
|
|
expect(url).toBe('/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).toBe('/README');
|
|
});
|
|
});
|
|
});
|