page-scroll-to.test.js 1004 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
const PAGE_PATH = '/pages/API/page-scroll-to/page-scroll-to'

describe('page-scroll-to', () => {
  let page
  beforeAll(async () => {
    page = await program.reLaunch(PAGE_PATH)
    await page.waitFor(500)
  })
  it('scroll-to', async () => {
    const btnScrollTo = await page.$('.btn-scrollTo')

    await btnScrollTo.tap()
13
    await page.waitFor(600)
14

15
    const scrollTop = await page.scrollTop()
16 17 18 19 20 21 22 23
    // 设备精度问题,允许上下浮动 1px
    expect(scrollTop > 99 && scrollTop < 101).toBe(true)
  })
  it('scroll-to-element', async () => {
    const btnScrollTo = await page.$('.btn-scrollToElement')
    const scrollToElement = await page.$('.custom-element')

    await btnScrollTo.tap()
24
    await page.waitFor(600)
25 26 27 28 29 30 31

    const offset = await scrollToElement.offset()
    // android 6 分辨率为 720*1280,需要调整期望数值
    if (!process.env.uniTestPlatformInfo.startsWith('android 6')) {
      expect(offset.top >= 1188).toBe(true)
    }
  })
32
})