-
Notifications
You must be signed in to change notification settings - Fork 1
GAUD-10062: expose waitForElem #993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,20 +36,20 @@ function getComposedChildren(node) { | |
| * @param {*} elem | ||
| * @param {boolean} awaitLoadingComplete | ||
| */ | ||
| async function waitForElem(elem, awaitLoadingComplete = true) { | ||
| export async function waitForElem(elem, awaitLoadingComplete = true) { | ||
|
|
||
| if (!elem) return; | ||
|
|
||
| const doWait = async() => { | ||
|
|
||
| const update = elem.updateComplete; | ||
| if (typeof update === 'object' && Promise.resolve(update) === update) { | ||
| await update; | ||
| if (awaitLoadingComplete && typeof elem.getLoadingComplete === 'function') { | ||
| await elem.getLoadingComplete(); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've also flipped the order here. We first wait for |
||
| await nextFrame(); | ||
| } | ||
|
|
||
| if (awaitLoadingComplete && typeof elem.getLoadingComplete === 'function') { | ||
| await elem.getLoadingComplete(); | ||
| const update = elem.updateComplete; | ||
| if (typeof update === 'object' && Promise.resolve(update) === update) { | ||
| await update; | ||
| await nextFrame(); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| import { defineCE, expect, fixture, html, waitUntil } from '../../src/browser/index.js'; | ||||||||||||||||||||||
| import { defineCE, expect, fixture, html, waitForElem, waitUntil } from '../../src/browser/index.js'; | ||||||||||||||||||||||
| import { LitElement, nothing } from 'lit'; | ||||||||||||||||||||||
| import { restore, stub } from 'sinon'; | ||||||||||||||||||||||
| import { focusElem } from '../../src/browser/commands.js'; | ||||||||||||||||||||||
|
|
@@ -64,6 +64,24 @@ const removedElem = defineCE( | |||||||||||||||||||||
| } | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const fastOrSlowElem = defineCE( | ||||||||||||||||||||||
| class extends LitElement { | ||||||||||||||||||||||
| static properties = { | ||||||||||||||||||||||
| slow: { type: Boolean } | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
| constructor() { | ||||||||||||||||||||||
| super(); | ||||||||||||||||||||||
| this.slow = false; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| render() { | ||||||||||||||||||||||
| if (this.slow) { | ||||||||||||||||||||||
| return unsafeHTML(`<${slowElem} id="slow">slow</${slowElem}>`); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| return html`<p>fast</p>`; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| describe('fixture', () => { | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| afterEach(() => restore()); | ||||||||||||||||||||||
|
|
@@ -332,6 +350,17 @@ describe('fixture', () => { | |||||||||||||||||||||
| expect(elem.querySelector(removedElem)).to.be.null; | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| it('should wait for elements that are updated to be slow', async() => { | ||||||||||||||||||||||
| const elem = await fixture(`<${fastOrSlowElem}></${fastOrSlowElem}>`); | ||||||||||||||||||||||
| expect(elem.shadowRoot.querySelector('p').textContent).to.equal('fast'); | ||||||||||||||||||||||
| elem.slow = true; | ||||||||||||||||||||||
| const waitPromise = waitForElem(elem); | ||||||||||||||||||||||
| await waitUntil(() => resolves.has('slow')); | ||||||||||||||||||||||
| timeouts.push(setTimeout(() => resolves.get('slow')(), 50)); | ||||||||||||||||||||||
| await waitPromise; | ||||||||||||||||||||||
| expect(elem.shadowRoot.querySelector(slowElem).finished).to.be.true; | ||||||||||||||||||||||
|
Comment on lines
+356
to
+361
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we be concerned that the
Suggested change
Like |
||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| describe('waitForFonts', () => { | ||||||||||||||||||||||
|
|
||||||||||||||||||||||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I was here...