Skip to content

Commit

Permalink
replace onceResized with nextResize
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen committed Dec 23, 2024
1 parent 8701fac commit 22886b8
Showing 1 changed file with 8 additions and 27 deletions.
35 changes: 8 additions & 27 deletions packages/component-base/test/resize-mixin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -53,13 +33,13 @@ describe('resize-mixin', () => {
beforeEach(async () => {
element = fixtureSync(`<resize-mixin-element></resize-mixin-element>`);
// 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;
});

Expand All @@ -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;
});

Expand Down Expand Up @@ -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;
});
});
Expand Down

0 comments on commit 22886b8

Please sign in to comment.