From 4722b9aba6f14ddbe86506b5f5870f210122baa0 Mon Sep 17 00:00:00 2001 From: web-padawan Date: Wed, 17 Jan 2024 12:04:18 +0200 Subject: [PATCH] Update Notification to expose define helper --- src/Notification.tsx | 9 +++++++-- test/Notification.spec.tsx | 23 +++++++++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Notification.tsx b/src/Notification.tsx index 601ac496..d5f07321 100644 --- a/src/Notification.tsx +++ b/src/Notification.tsx @@ -52,12 +52,17 @@ type NotificationShow = { }; export type NotificationFunction = ForwardRefExoticComponent> & - NotificationShow; + NotificationShow & { + define(): Promise; + }; const ForwardedNotification = forwardRef(Notification) as NotificationFunction; + +Object.assign(ForwardedNotification, { define: _Notification.define }); + ForwardedNotification.show = async function (contents: string, options?: ShowOptions) { - await _Notification.define(); + await ForwardedNotification.define(); const Notification = customElements.get('vaadin-notification') as unknown as NotificationShow; return Notification.show(contents, options); }; diff --git a/test/Notification.spec.tsx b/test/Notification.spec.tsx index a0b277b7..ab7aeed3 100644 --- a/test/Notification.spec.tsx +++ b/test/Notification.spec.tsx @@ -15,43 +15,38 @@ describe('Notification', () => { return <>FooBar; } - async function until(predicate: () => boolean) { - while (!predicate()) { - await new Promise((r) => setTimeout(r, 10)); - } - } - - async function assert() { - await until(() => !!document.querySelector('vaadin-notification-card')); + function assert() { const card = document.querySelector('vaadin-notification-card'); expect(card).to.exist; expect(card).to.have.text('FooBar'); } + before(Notification.define); + afterEach(cleanup); afterEach(catcher); - it('should use children if no renderer property set', async () => { + it('should use children if no renderer property set', () => { render( FooBar , ); - await assert(); + assert(); }); - it('should use renderer prop if it is set', async () => { + it('should use renderer prop if it is set', () => { render(); - await assert(); + assert(); }); - it('should use children render function as a renderer prop', async () => { + it('should use children render function as a renderer prop', () => { render( {Renderer} , ); - await assert(); + assert(); }); describe('show()', () => {