docsify/test/integration/docsify.test.js
John Hildenbiddle bb902f8997
refactor: event modernization and optimization (#2404)
- Refactor methods names and functionality
- Replace scroll listeners with observers
- Replace Tweezer-based scrolling with native scroll methods
- Remove tweezer.js dependency
- Remove redundant method calls
- Rename $resetEvents to onNavigate
- Rename __scrollActiveSidebar to onRender
- Remove __getAndActive
- Remove __sticky
- Add IntersectionObserver mock to Jest environment

Also included:

- Add e2e test “ui” and “chromium” scripts
- Rename "jest" script to "test:jest"
- Remove unused SSR code

---------

Co-authored-by: Koy Zhuang <koy@ko8e24.top>
2024-04-21 07:44:14 -05:00

53 lines
1.5 KiB
JavaScript

import { jest } from '@jest/globals';
import docsifyInit from '../helpers/docsify-init.js';
// Suite
// -----------------------------------------------------------------------------
describe('Docsify', function () {
// Tests
// ---------------------------------------------------------------------------
test('allows $docsify configuration to be a function', async () => {
const testConfig = jest.fn(vm => {
expect(vm).toBeInstanceOf(Object);
expect(vm.constructor.name).toBe('Docsify');
expect(vm.$fetch).toBeInstanceOf(Function);
expect(vm.route).toBeInstanceOf(Object);
});
await docsifyInit({
config: testConfig,
});
expect(typeof Docsify).toBe('object');
expect(testConfig).toHaveBeenCalled();
});
test('provides the hooks and vm API to plugins', async () => {
const testConfig = jest.fn(vm => {
const vm1 = vm;
return {
plugins: [
function (hook, vm2) {
expect(vm1).toEqual(vm2);
expect(hook.init).toBeInstanceOf(Function);
expect(hook.beforeEach).toBeInstanceOf(Function);
expect(hook.afterEach).toBeInstanceOf(Function);
expect(hook.doneEach).toBeInstanceOf(Function);
expect(hook.mounted).toBeInstanceOf(Function);
expect(hook.ready).toBeInstanceOf(Function);
},
],
};
});
await docsifyInit({
config: testConfig,
});
expect(typeof Docsify).toBe('object');
expect(testConfig).toHaveBeenCalled();
});
});