create-intersection-observer.test.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  2. const isAndroid = platformInfo.startsWith('android')
  3. const isIOS = platformInfo.startsWith('ios')
  4. const isHarmony = platformInfo.startsWith('harmony')
  5. const isApp = isAndroid || isIOS || isHarmony
  6. describe('API-intersection-observer', () => {
  7. if (isApp) {
  8. it('not support', () => {
  9. expect(1).toBe(1)
  10. })
  11. return
  12. }
  13. let page;
  14. beforeAll(async () => {
  15. page = await program.reLaunch('/pages/API/create-intersection-observer/create-intersection-observer')
  16. await page.waitFor('view');
  17. });
  18. it('scroll-to-show-ball', async () => {
  19. await page.setData({scrollTop: 180})
  20. await page.waitFor(500)
  21. // 微信小程序端,仅在基础库3.5.8及以下版本支持scrollTo方法
  22. // const scrollView = await page.$('.scroll-view')
  23. // await scrollView.scrollTo(0, 200)
  24. const appear = await page.data('appear')
  25. expect(appear).toBe(true)
  26. const testRes = await page.data('testRes')
  27. expect(testRes.intersectionRatio).toBeGreaterThan(0)
  28. expect(testRes.intersectionRect).toBeDefined()
  29. expect(testRes.boundingClientRect).toBeDefined()
  30. expect(testRes.relativeRect).toBeDefined()
  31. expect(testRes.boundingClientRect.bottom).toBeDefined()
  32. expect(testRes.boundingClientRect.left).toBeDefined()
  33. expect(testRes.boundingClientRect.right).toBeDefined()
  34. expect(testRes.boundingClientRect.top).toBeDefined()
  35. })
  36. });