-
Notifications
You must be signed in to change notification settings - Fork 291
/
toClick.test.js
66 lines (57 loc) · 2.1 KB
/
toClick.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { setupPage } from './setupPage'
describe('toClick', () => {
beforeEach(async () => {
await page.goto(`http://localhost:${process.env.TEST_SERVER_PORT}`)
})
describe.each(['Page', 'Frame'])('%s', pageType => {
let page
setupPage(pageType, ({ currentPage }) => {
page = currentPage
})
it('should click using selector', async () => {
await expect(page).toClick('a[href="/page2.html"]')
await page.waitForNavigation()
const pathname = await page.evaluate(() => document.location.pathname)
expect(pathname).toBe('/page2.html')
})
it('should click using text', async () => {
await expect(page).toClick('a', { text: 'Page 2' })
await page.waitForNavigation()
const pathname = await page.evaluate(() => document.location.pathname)
expect(pathname).toBe('/page2.html')
})
it('should return an error if element is not found', async () => {
expect.assertions(2)
try {
await expect(page).toClick('a', { text: 'Nop' })
} catch (error) {
expect(error.message).toMatch('Element a (text: "Nop") not found')
}
})
})
describe('ElementHandle', () => {
it('should click using selector', async () => {
const body = await page.$('body')
await expect(body).toClick('a[href="/page2.html"]')
await page.waitForSelector('html')
const pathname = await page.evaluate(() => document.location.pathname)
expect(pathname).toBe('/page2.html')
})
it('should click using text', async () => {
const body = await page.$('body')
await expect(body).toClick('a', { text: 'Page 2' })
await page.waitForSelector('html')
const pathname = await page.evaluate(() => document.location.pathname)
expect(pathname).toBe('/page2.html')
})
it('should return an error if element is not found', async () => {
const body = await page.$('body')
expect.assertions(2)
try {
await expect(body).toClick('a', { text: 'Nop' })
} catch (error) {
expect(error.message).toMatch('Element a (text: "Nop") not found')
}
})
})
})