MCPcopy
hub / github.com/codeceptjs/CodeceptJS / waitCurrentPathEquals

Method waitCurrentPathEquals

lib/helper/Puppeteer.js:2554–2578  ·  view source on GitHub ↗

* {{> waitCurrentPathEquals }}

(path, sec = null)

Source from the content-addressed store, hash-verified

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 }}

Callers 1

testsFunction · 0.45

Calls 3

_getPageUrlMethod · 0.95
normalizePathFunction · 0.90
waitForFunctionMethod · 0.45

Tested by

no test coverage detected