Skip to content

Commit 2d525b3

Browse files
committed
tests: add test for wait
1 parent aec552c commit 2d525b3

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

test/fixtures/late-page.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
<span>Loading...</span>
5+
<script>
6+
setTimeout(() => {
7+
const loaded = document.createElement('span')
8+
loaded.textContent = 'Loaded!'
9+
document.body.appendChild(loaded)
10+
}, 5000)
11+
</script>
12+
</body>
13+
</html>

test/index.test.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as path from 'path'
22
import * as puppeteer from 'puppeteer'
3-
import {getDocument, queries, getQueriesForElement} from '../lib'
3+
import {getDocument, queries, getQueriesForElement, wait} from '../lib'
44

55
describe('lib/index.ts', () => {
66
let browser: puppeteer.Browser
@@ -24,6 +24,16 @@ describe('lib/index.ts', () => {
2424
expect(await queries.getNodeText(element)).toEqual('Hello h1')
2525
})
2626

27+
it('should load the defered page', async () => {
28+
await page.goto(`file://${path.join(__dirname, 'fixtures/late-page.html')}`)
29+
})
30+
31+
it('should use `wait` properly', async () => {
32+
const {getByText} = getQueriesForElement(await getDocument(page))
33+
await wait(() => getByText('Loaded!'))
34+
expect(await getByText('Loaded!')).toBeTruthy()
35+
}, 7000)
36+
2737
afterAll(async () => {
2838
await browser.close()
2939
})

0 commit comments

Comments
 (0)