diff --git a/packages/component-base/test/resize-mixin.test.js b/packages/component-base/test/resize-mixin.test.js index 5743eb99f1..1e0e01dc38 100644 --- a/packages/component-base/test/resize-mixin.test.js +++ b/packages/component-base/test/resize-mixin.test.js @@ -2,29 +2,9 @@ import { expect } from '@vaadin/chai-plugins'; import { aTimeout, fixtureSync, nextFrame } from '@vaadin/testing-helpers'; import sinon from 'sinon'; import { html, PolymerElement } from '@polymer/polymer/polymer-element.js'; +import { nextResize } from '../../grid/test/helpers.js'; import { ResizeMixin } from '../src/resize-mixin.js'; -/** - * Resolves once the function is invoked on the given object. - */ -function onceInvoked(object, functionName) { - return new Promise((resolve) => { - sinon.replace(object, functionName, (...args) => { - sinon.restore(); - object[functionName](...args); - resolve(); - }); - }); -} - -/** - * Resolves once the ResizeObserver in AvatarGroup has processed a resize. - */ -async function onceResized(el) { - // Wait for the _onResize function to be invoked by the ResizeObserver - await onceInvoked(el, '_onResize'); -} - describe('resize-mixin', () => { let element, observeParent; @@ -53,13 +33,13 @@ describe('resize-mixin', () => { beforeEach(async () => { element = fixtureSync(``); // Wait for the initial resize. - await onceResized(element); + await nextResize(); }); it('should notify resize', async () => { const spy = sinon.spy(element, '_onResize'); element.style.width = '100px'; - await onceResized(element); + await nextResize(); expect(spy.calledOnce).to.be.true; }); @@ -83,13 +63,14 @@ describe('resize-mixin', () => { beforeEach(async () => { parent.appendChild(element); // Wait for the initial resize. - await onceResized(element); + await nextResize(); + // await nextResize(); }); it('should notify parent element resize', async () => { const spy = sinon.spy(element, '_onResize'); parent.style.width = '100px'; - await onceResized(element); + await nextResize(); expect(spy.calledOnce).to.be.true; }); @@ -130,13 +111,13 @@ describe('resize-mixin', () => { parent.attachShadow({ mode: 'open' }); parent.shadowRoot.appendChild(element); // Wait for the initial resize. - await onceResized(element); + await nextResize(); }); it('should notify shadow host resize', async () => { const spy = sinon.spy(element, '_onResize'); parent.style.width = '100px'; - await onceResized(element); + await nextResize(); expect(spy.calledOnce).to.be.true; }); });