Skip to content

Commit

Permalink
Moved test and added existing check
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Mar 26, 2020
1 parent 6c951da commit c4b6b42
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 27 deletions.
67 changes: 67 additions & 0 deletions test/pseudo-window.body.spec.js
Original file line number Diff line number Diff line change
@@ -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: `
<div>
<pseudo-window
body
@click="clickHandler"
/>
</div>
`,
components: {
PseudoWindow,
},
methods: {
clickHandler,
},
}, {
attachToDocument: true,
});

global.window.document.body.dispatchEvent(new Event('click'));
expect(clickHandler).toHaveBeenCalled();
});
});

describe('Class', () => {
it('invalid', async () => {
mount({
template: `
<pseudo-window
class="static-class"
/>
`,
components: {
PseudoWindow,
},
});

const { classList } = global.window.document.body;
expect(classList.contains('static-class')).toBe(false);
});

it('static class', async () => {
const wrapper = mount({
template: `
Expand Down Expand Up @@ -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: `
<pseudo-window
body
class="static-class"
/>
`,
components: {
PseudoWindow,
},
});

expect(classList.contains('static-class')).toBe(true);

wrapper.destroy();

expect(classList.contains('should-remain')).toBe(true);
});
});
27 changes: 0 additions & 27 deletions test/pseudo-window.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: `
<div>
<pseudo-window
body
@click="clickHandler"
/>
</div>
`,
components: {
PseudoWindow,
},
methods: {
clickHandler,
},
}, {
attachToDocument: true,
});

global.window.document.body.dispatchEvent(new Event('click'));
expect(clickHandler).toHaveBeenCalled();
});
});

0 comments on commit c4b6b42

Please sign in to comment.