* {{> waitCurrentPathEquals }}
(path, sec = null)
| 2552 | * {{> waitCurrentPathEquals }} |
| 2553 | */ |
| 2554 | async waitCurrentPathEquals(path, sec = null) { |
| 2555 | const waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout |
| 2556 | const normalizedPath = normalizePath(path) |
| 2557 | |
| 2558 | return this.page |
| 2559 | .waitForFunction( |
| 2560 | expectedPath => { |
| 2561 | const actualPath = window.location.pathname |
| 2562 | const normalizePath = p => (p === '' || p === '/' ? '/' : p.replace(/\/+/g, '/').replace(/\/$/, '') || '/') |
| 2563 | return normalizePath(actualPath) === expectedPath |
| 2564 | }, |
| 2565 | { timeout: waitTimeout }, |
| 2566 | normalizedPath, |
| 2567 | ) |
| 2568 | .catch(async e => { |
| 2569 | const currUrl = await this._getPageUrl() |
| 2570 | const baseUrl = this.options.url || 'http://localhost' |
| 2571 | const actualPath = new URL(currUrl, baseUrl).pathname |
| 2572 | if (/Waiting failed/i.test(e.message) || /failed: timeout/i.test(e.message)) { |
| 2573 | throw new Error(`expected path to be ${normalizedPath}, but found ${normalizePath(actualPath)}`) |
| 2574 | } else { |
| 2575 | throw e |
| 2576 | } |
| 2577 | }) |
| 2578 | } |
| 2579 | |
| 2580 | /** |
| 2581 | * {{> waitForText }} |
no test coverage detected