Skip to content

Commit 51f64e1

Browse files
committed
Wait for OPENED event instead of sleeping
1 parent 29cc5b0 commit 51f64e1

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

packages/uui-toast-notification/lib/uui-toast-notification.test.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,14 @@ describe('UUIToastNotificationElement', () => {
220220

221221
element.pauseAutoClose();
222222

223-
await sleep(600); // enough time for opening animation to be done.
223+
// Wait for OPENED event
224+
const openedListener = oneEvent(element, UUIToastNotificationEvent.OPENED);
225+
const openedEvent = await openedListener;
226+
expect(openedEvent).to.exist;
227+
expect(openedEvent.type).to.equal(UUIToastNotificationEvent.OPENED);
224228

225229
element.resumeAutoClose();
226-
expect(element.open).to.be.true;
230+
expect(element.open, 'Element should still be open immediately after resuming').to.be.true;
227231

228232
const closeListener = oneEvent(
229233
element,
@@ -251,7 +255,12 @@ describe('UUIToastNotificationElement', () => {
251255
it('clicking on the close-button did close', async () => {
252256
element.open = true;
253257

254-
await sleep(100); // wait a bit.
258+
// Wait for OPENED event
259+
const openedListener = oneEvent(element, UUIToastNotificationEvent.OPENED);
260+
const openedEvent = await openedListener;
261+
expect(openedEvent).to.exist;
262+
expect(openedEvent.type).to.equal(UUIToastNotificationEvent.OPENED);
263+
255264
expect(element.open).to.be.true;
256265

257266
const closeButton = element.shadowRoot!.querySelector(
@@ -267,7 +276,12 @@ describe('UUIToastNotificationElement', () => {
267276
it('pressing esc when focus did close', async () => {
268277
element.open = true;
269278

270-
await sleep(100); // wait a bit.
279+
// Wait for OPENED event
280+
const openedListener = oneEvent(element, UUIToastNotificationEvent.OPENED);
281+
const openedEvent = await openedListener;
282+
expect(openedEvent).to.exist;
283+
expect(openedEvent.type).to.equal(UUIToastNotificationEvent.OPENED);
284+
271285
expect(element.open).to.be.true;
272286

273287
element.dispatchEvent(new KeyboardEvent('keyup', { key: 'Escape' }));

0 commit comments

Comments
 (0)