docsify/test/unit/router-history-base.test.js
Joe Pea 62d756c447 refactor: convert to ES Modules and remove traces of CommonJS except in Rollup config because some dependencies are still CommonJS
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.
2023-06-29 19:02:08 -07:00

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');
});
});
});