diff --git a/test/pseudo-window.body.spec.js b/test/pseudo-window.body.spec.js index 9815b55..8e905c2 100644 --- a/test/pseudo-window.body.spec.js +++ b/test/pseudo-window.body.spec.js @@ -1,7 +1,50 @@ import { mount } from '@vue/test-utils'; import PseudoWindow from 'vue-pseudo-window'; +describe('Events', () => { + it('should catch "click" on body', () => { + const clickHandler = jest.fn(); + mount({ + template: ` +
+ +
+ `, + components: { + PseudoWindow, + }, + methods: { + clickHandler, + }, + }, { + attachToDocument: true, + }); + + global.window.document.body.dispatchEvent(new Event('click')); + expect(clickHandler).toHaveBeenCalled(); + }); +}); + describe('Class', () => { + it('invalid', async () => { + mount({ + template: ` + + `, + components: { + PseudoWindow, + }, + }); + + const { classList } = global.window.document.body; + expect(classList.contains('static-class')).toBe(false); + }); + it('static class', async () => { const wrapper = mount({ template: ` @@ -89,4 +132,28 @@ describe('Class', () => { expect(classList.contains('reactive-class')).toBe(false); }); + + + it('work with existing class', async () => { + const { classList } = global.window.document.body; + classList.add('should-remain'); + + const wrapper = mount({ + template: ` + + `, + components: { + PseudoWindow, + }, + }); + + expect(classList.contains('static-class')).toBe(true); + + wrapper.destroy(); + + expect(classList.contains('should-remain')).toBe(true); + }); }); diff --git a/test/pseudo-window.spec.js b/test/pseudo-window.spec.js index 06726ff..811fb65 100644 --- a/test/pseudo-window.spec.js +++ b/test/pseudo-window.spec.js @@ -242,30 +242,3 @@ describe('Document', () => { expect(clickHandler.mock.calls.length).toBe(3); }); }); - -describe('Body', () => { - it('should catch "click" on body', () => { - const clickHandler = jest.fn(); - mount({ - template: ` -
- -
- `, - components: { - PseudoWindow, - }, - methods: { - clickHandler, - }, - }, { - attachToDocument: true, - }); - - global.window.document.body.dispatchEvent(new Event('click')); - expect(clickHandler).toHaveBeenCalled(); - }); -});