docsify/test/integration/docsify.test.js
Joe Pea 00a87311b0 allow the el option to accept an HTMLElement instance
This aligns it with what the docs were already saying erroneously, plus
this is useful in cases when people have refs to an element already
(embedding Docsify in a custom element shadow root, or in a React
component that has a ref to the target element, etc).
2022-01-05 09:55:48 -08:00

76 lines
2.1 KiB
JavaScript

const docsifyInit = require('../helpers/docsify-init');
describe('Docsify', function() {
describe('config options', () => {
test('allows $docsify configuration to be a function', async () => {
const testConfig = jest.fn(vm => {
expect(vm).toBeInstanceOf(Object);
expect(vm.constructor.name).toEqual('Docsify');
expect(vm.$fetch).toBeInstanceOf(Function);
expect(vm.$resetEvents).toBeInstanceOf(Function);
expect(vm.route).toBeInstanceOf(Object);
});
await docsifyInit({
config: testConfig,
});
expect(typeof Docsify).toEqual('object');
expect(testConfig).toHaveBeenCalled();
});
describe('config.el', () => {
it('accepts an element instance', async () => {
const config = jest.fn(() => {
const app = document.querySelector('#app');
expect(app).toBeInstanceOf(HTMLElement);
return {
basePath: `${TEST_HOST}/docs/index.html#/`,
el: app,
};
});
await docsifyInit({
config,
testURL: `${TEST_HOST}/docs/index.html#/`,
});
expect(config).toHaveBeenCalled();
expect(document.querySelector('#main').textContent).toContain(
'A magical documentation site generator.'
);
});
});
});
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).toEqual('object');
expect(testConfig).toHaveBeenCalled();
});
});