-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.e2e.spec.ts
54 lines (49 loc) · 1.49 KB
/
index.e2e.spec.ts
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
import serverAndBrowser, { Page, StopFn } from '../../utils/e2e-setup'
import { addAttach } from 'jest-html-reporters/helper'
import path from 'path'
describe('Flex 布局', () => {
let stop: StopFn
let page: Page
beforeAll(async () => {
const res = await serverAndBrowser({
rootPath: path.join(__dirname, 'code'),
port: 3000
})
stop = res.stop
page = res.page
})
afterAll(async () => {
await stop()
})
test('主轴是行方向的在一列', async () => {
// 将截图附到测试报告中。
if (process.env.TYPE === 'report') {
const filePath = path.resolve(__dirname, './flex.jpg')
await page.screenshot({ path: filePath })
await addAttach(filePath, 'flex pic')
}
const posYArr = await page.evaluate(() => {
const items = document.querySelectorAll('.ly>.item')
return [
items[0].getBoundingClientRect().top,
items[1].getBoundingClientRect().top,
items[2].getBoundingClientRect().top
]
})
expect(posYArr[0]).toBe(posYArr[1])
expect(posYArr[1]).toBe(posYArr[2])
})
test('flex grow 撑满剩余空间', async () => {
const {
flexGrowItemWidth,
resetWidth
} = await page.evaluate(() => {
const flexGrowItem = document.querySelector('.ly>.flex-grow-item')
return {
flexGrowItemWidth: flexGrowItem.clientWidth,
resetWidth: document.body.clientWidth - 2 * 100 - 3 * 10
}
})
expect(flexGrowItemWidth).toBe(resetWidth)
})
})