Skip to content

Commit

Permalink
Added tests for waitForResize
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmay-browserstack committed Sep 27, 2024
1 parent c8037bc commit fe05534
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion packages/dom/test/serialize-dom.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { withExample, replaceDoctype, createShadowEl, getTestBrowser, chromeBrowser, parseDOM } from './helpers';
import serializeDOM from '@percy/dom';
import serializeDOM, { waitForResize } from '@percy/dom';

describe('serializeDOM', () => {
it('returns serialied html, warnings, and resources', () => {
Expand Down Expand Up @@ -350,6 +350,28 @@ describe('serializeDOM', () => {
});
});

describe('waitForResize', () => {
it('updates window.resizeCount', async () => {
waitForResize();
expect(window.resizeCount).toEqual(0);
// trigger resize event
// eslint-disable-next-line no-undef
window.dispatchEvent(new Event('resize'));
// eslint-disable-next-line no-undef
window.dispatchEvent(new Event('resize'));
// should be only updated once in 100ms
await new Promise((r) => setTimeout(r, 150));
expect(window.resizeCount).toEqual(1);
waitForResize();
expect(window.resizeCount).toEqual(0);
// eslint-disable-next-line no-undef
window.dispatchEvent(new Event('resize'));
await new Promise((r) => setTimeout(r, 150));
// there should only one event listener added
expect(window.resizeCount).toEqual(1);
});
});

describe('error handling', () => {
it('adds node details in error message and rethrow it', () => {
let oldURL = window.URL;
Expand Down

0 comments on commit fe05534

Please sign in to comment.