chore: don't let count() throw during navigation#36941
chore: don't let count() throw during navigation#36941Skn0tt merged 5 commits intomicrosoft:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
||
| async _queryCount(selector: string): Promise<number> { | ||
| return (await this._channel.queryCount({ selector })).value; | ||
| async _queryCount(selector: string, options?: any): Promise<number> { |
There was a problem hiding this comment.
Instead of any, let's make it {} everywhere to designate we do not expect anything meaningful there.
|
|
||
| async count(): Promise<number> { | ||
| return await this._frame._queryCount(this._selector); | ||
| async count(options?: any): Promise<number> { |
There was a problem hiding this comment.
Let's add a comment that options are here only for testing.
| // Be careful, |this.frame| can be different from |resolved.frame|. | ||
| if (!resolved) | ||
| throw new Error(`Failed to find frame for selector "${selector}"`); | ||
| await options.__testHookAfterStable?.(); |
There was a problem hiding this comment.
I find the current hook name unsuitable.
| await options.__testHookAfterStable?.(); | |
| await options.__testHookBeforeQuery?.(); |
| try { | ||
| return await this.selectors.queryCount(selector, options); | ||
| } catch { | ||
| return 0; |
There was a problem hiding this comment.
You should check isNonRetriableError() here. See how isVisibleInternal() does it. Let's add a test that count() throws on page closure.
| .contentFrame().locator('#f0_mid_0') | ||
| .contentFrame().locator('text=L28').or(l('text=L29'))))); | ||
| const error = await locator.count().catch(e => e); | ||
| const error = await locator.isHidden().catch(e => e); |
There was a problem hiding this comment.
Let's revert, this one should still throw.
tests/page/locator-query.spec.ts
Outdated
| await page.setContent(`<div>A</div>`); | ||
| let triggered = false; | ||
| const __testHookAfterStable = () => { | ||
| if (triggered) |
There was a problem hiding this comment.
How could this hook be called twice?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Test results for "tests 1"1 failed 45 flaky46610 passed, 805 skipped Merge workflow run. |
Closes #36851