Skip to content
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

chore(iframe): await window.request to be set #2252

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions test/browser/msw-api/setup-worker/scenarios/iframe/iframe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ test('intercepts a request from an iframe (nested client)', async ({
})

const frame = page.mainFrame().childFrames().find(findFrame)!

/**
* @note Explicitly wait for the `window.request` to be set by the iframe.
* Looks like Playwright won't wait for iframes loading, and this causes
* this test to fail sometimes.
*/
await page.waitForFunction(() => typeof window.request === 'function')
await frame.evaluate(() => window.request())

const firstNameElement = await frame.waitForSelector('#first-name')
Expand All @@ -55,6 +62,7 @@ test('intercepts a request from a deeply nested iframe', async ({
.childFrames()
.find(findFrame)!

await page.waitForFunction(() => typeof window.request === 'function')
await deepFrame.evaluate(() => window.request())
const firstNameElement = await deepFrame.waitForSelector('#first-name')
const firstName = await firstNameElement.evaluate((node) => node.textContent)
Expand All @@ -81,6 +89,7 @@ test('intercepts a request from a deeply nested iframe given MSW is registered i
})

const deepFrame = page.mainFrame().childFrames().find(findFrame)!
await page.waitForFunction(() => typeof window.request === 'function')
await deepFrame.evaluate(() => window.request())
const firstNameElement = await deepFrame.waitForSelector('#first-name')
const firstName = await firstNameElement.evaluate((node) => node.textContent)
Expand Down Expand Up @@ -123,6 +132,7 @@ test('intercepts a request from an iframe given MSW is registered in a sibling i
.childFrames()
.find(findFrame)!

await page.waitForFunction(() => typeof window.request === 'function')
await frame.evaluate(() => window.request())
const firstNameElement = await frame.waitForSelector('#first-name')
const firstName = await firstNameElement.evaluate((node) => node.textContent)
Expand Down
Loading