diff --git a/test/config/jest.setup-tests.js b/test/config/jest.setup-tests.js index 3fbeaaa99..f72ed4787 100644 --- a/test/config/jest.setup-tests.js +++ b/test/config/jest.setup-tests.js @@ -21,8 +21,32 @@ const sideEffects = { }, }; +class IntersectionObserver { + constructor() {} + + root = null; + rootMargin = ''; + thresholds = []; + + disconnect() { + return null; + } + + observe() { + return null; + } + + takeRecords() { + return []; + } + + unobserve() { + return null; + } +} + // Lifecycle Hooks -// ----------------------------------------------------------------------------- +// ============================================================================= beforeAll(async () => { // Spy addEventListener ['document', 'window'].forEach(obj => { @@ -44,13 +68,16 @@ beforeAll(async () => { }); }); -// Reset JSDOM. This attempts to remove side effects from tests, however it does -// not reset all changes made to globals like the window and document -// objects. Tests requiring a full JSDOM reset should be stored in separate -// files, which is only way to do a complete JSDOM reset with Jest. beforeEach(async () => { const rootElm = document.documentElement; + // Reset JSDOM + // ----------------------------------------------------------------------------- + // This attempts to remove side effects from tests, however it does not reset + // all changes made to globals like the window and document objects. Tests + // requiring a full JSDOM reset should be stored in separate files, which is + // only way to do a complete JSDOM reset with Jest. + // Remove attributes on root element [...rootElm.attributes].forEach(attr => rootElm.removeAttribute(attr.name)); @@ -79,6 +106,12 @@ beforeEach(async () => { // Restore base elements rootElm.innerHTML = ''; + + // Mock IntersectionObserver + // ----------------------------------------------------------------------------- + [global, window].forEach( + obj => (obj.IntersectionObserver = IntersectionObserver) + ); }); afterEach(async () => { diff --git a/test/integration/docsify.test.js b/test/integration/docsify.test.js index 06d32d2ba..438030314 100644 --- a/test/integration/docsify.test.js +++ b/test/integration/docsify.test.js @@ -11,7 +11,6 @@ describe('Docsify', function () { expect(vm).toBeInstanceOf(Object); expect(vm.constructor.name).toBe('Docsify'); expect(vm.$fetch).toBeInstanceOf(Function); - expect(vm.$resetEvents).toBeInstanceOf(Function); expect(vm.route).toBeInstanceOf(Object); });