* {{> waitCurrentPathEquals }}
(path, sec = null)
| 3470 | * {{> waitCurrentPathEquals }} |
| 3471 | */ |
| 3472 | async waitCurrentPathEquals(path, sec = null) { |
| 3473 | const waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout |
| 3474 | const normalizedPath = normalizePath(path) |
| 3475 | |
| 3476 | try { |
| 3477 | await this.page.waitForFunction( |
| 3478 | expectedPath => { |
| 3479 | const actualPath = window.location.pathname |
| 3480 | const normalizePath = p => (p === '' || p === '/' ? '/' : p.replace(/\/+/g, '/').replace(/\/$/, '') || '/') |
| 3481 | return normalizePath(actualPath) === expectedPath |
| 3482 | }, |
| 3483 | normalizedPath, |
| 3484 | { timeout: waitTimeout }, |
| 3485 | ) |
| 3486 | } catch (e) { |
| 3487 | const currentUrl = await this._getPageUrl() |
| 3488 | const baseUrl = this.options.url || 'http://localhost' |
| 3489 | const actualPath = new URL(currentUrl, baseUrl).pathname |
| 3490 | if (/Timeout/i.test(e.message)) { |
| 3491 | throw new Error(`expected path to be ${normalizedPath}, but found ${normalizePath(actualPath)}`) |
| 3492 | } else { |
| 3493 | throw e |
| 3494 | } |
| 3495 | } |
| 3496 | } |
| 3497 | |
| 3498 | /** |
| 3499 | * {{> waitForText }} |
nothing calls this directly
no test coverage detected