Skip to content

Commit b034827

Browse files
committed
test(fixture): add coverage for auto-waiting with queryBy
1 parent c6a5736 commit b034827

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

test/fixture/locators.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,15 @@ test.describe('lib/fixture.ts (locators)', () => {
214214
expect(await locator.textContent()).toEqual('Loaded!')
215215
})
216216

217+
test("queryBy* methods can be used with Playwright's laziness", async ({screen, within}) => {
218+
const modalLocator = await screen.findByRole('dialog', undefined, {timeout: 3000})
219+
220+
await expect(modalLocator).toHaveText(/My Modal/)
221+
await within(modalLocator).getByRole('button', {name: 'Okay'}).click()
222+
223+
await expect(screen.queryByRole('dialog')).toBeHidden()
224+
})
225+
217226
test('should handle the findAllBy* methods', async ({queries}) => {
218227
const locator = await queries.findAllByText(/Hello/, undefined, {timeout: 3000})
219228

test/fixtures/late-page.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,25 @@
2525
attached.textContent = 'Attached'
2626
attached.style.visibility = 'hidden'
2727
document.body.appendChild(attached)
28+
29+
const modal = document.createElement('dialog')
30+
const modalButton = document.createElement('button')
31+
const modalHeader = document.createElement('h1')
32+
33+
modal.style.display = 'block'
34+
35+
modalButton.innerText = 'Okay'
36+
modalButton.onclick = () => {
37+
modal.innerText = 'Doing a thing...'
38+
setTimeout(() => document.querySelector('dialog').remove(), 1000)
39+
}
40+
41+
modalHeader.innerText = 'My Modal'
42+
43+
modal.appendChild(modalButton)
44+
modal.appendChild(modalHeader)
45+
46+
document.body.appendChild(modal)
2847
}, 2000)
2948
</script>
3049
</body>

0 commit comments

Comments
 (0)