component.test.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. describe('pages/tabBar/component/component.nvue', () => {
  2. let page
  3. beforeAll(async () => {
  4. // 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
  5. page = await program.reLaunch('/pages/tabBar/component/component')
  6. await page.waitFor(1000)
  7. })
  8. it('u-link', async () => {
  9. // 检测首页u-link的文本内容
  10. expect(await (await page.$('.hello-link')).text()).toBe(
  11. 'https://uniapp.dcloud.io/component/')
  12. })
  13. it('视图容器', async () => {
  14. let panelText = await page.$('.uni-panel-text')
  15. // 检测首个 panel 是视图容器
  16. expect(await panelText.text()).toBe(
  17. '视图容器')
  18. // 检测首个 panel 切换展开
  19. const panelH = await page.$('.uni-panel-h');
  20. // 不能做完全匹配,百度小程序会生成额外的class
  21. expect(await panelH.attribute('class')).toContain('uni-panel-h')
  22. await panelH.tap()
  23. await page.waitFor(500)
  24. // 已展开
  25. expect(await panelH.attribute('class')).toContain('uni-panel-h-on')
  26. })
  27. // it('.uni-panel', async () => {
  28. // const lists = await page.$$('.uni-panel')
  29. // expect(lists.length).toBe(9)
  30. // })
  31. it('.uni-panel action', async () => {
  32. const listHead = await page.$('.uni-panel-h')
  33. expect(await listHead.attribute('class')).toContain('uni-panel-h-on')
  34. await listHead.tap()
  35. await page.waitFor(200)
  36. expect(await listHead.attribute('class')).toContain(
  37. 'uni-panel-h',
  38. )
  39. // 展开第一个 panel,点击第一个 item,验证打开的新页面是否正确
  40. await listHead.tap()
  41. await page.waitFor(200)
  42. const item = await page.$('.uni-navigate-item')
  43. await item.tap()
  44. await page.waitFor(500)
  45. expect((await program.currentPage()).path).toBe('pages/component/view/view')
  46. await page.waitFor(500)
  47. // 执行 navigateBack 验证是否返回
  48. expect((await program.navigateBack()).path).toBe('pages/tabBar/component/component')
  49. })
  50. })