describe('pages/tabBar/component/component.nvue', () => { let page, containsVite, isApp; containsVite = process.env.UNI_CLI_PATH.includes('uniapp-cli-vite') isApp = process.env.UNI_PLATFORM.includes('app') if (containsVite && isApp) { it('vue3', async () => { expect(1).toBe(1) }) return } beforeAll(async () => { // 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象) page = await program.reLaunch('/pages/tabBar/component/component') await page.waitFor("view") }) it('u-link', async () => { // 检测首页u-link的文本内容 expect(await (await page.$('.hello-link')).text()).toBe('https://uniapp.dcloud.io/component/') }) it('视图容器', async () => { let panelText = await page.$('.uni-panel-text') // 检测首个 panel 是视图容器 expect(await panelText.text()).toBe( '视图容器') // 检测首个 panel 切换展开 const panelH = await page.$('.uni-panel-h'); // 不能做完全匹配,百度小程序会生成额外的class expect(await panelH.attribute('class')).toContain('uni-panel-h') await panelH.tap() await page.waitFor(500) // 已展开 expect(await panelH.attribute('class')).toContain('uni-panel-h-on') }) it('.uni-panel', async () => { const lists = await page.$$('.uni-panel') if(process.env.UNI_PLATFORM == 'app-plus' || process.env.UNI_PLATFORM == 'mp-weixin'){ expect(lists.length).toBe(9) }else if(process.env.UNI_PLATFORM == 'h5' && !containsVite){ expect(lists.length).toBe(8) } }) it('.uni-panel action', async () => { const listHead = await page.$('.uni-panel-h') expect(await listHead.attribute('class')).toContain('uni-panel-h-on') await listHead.tap() await page.waitFor(200) expect(await listHead.attribute('class')).toContain('uni-panel-h') // 展开第一个 panel,点击第一个 item,验证打开的新页面是否正确 await listHead.tap() await page.waitFor(200) const item = await page.$('.uni-navigate-item') await item.tap() await page.waitFor(500) expect((await program.currentPage()).path).toBe('pages/component/view/view') await page.waitFor(500) // 执行 navigateBack 验证是否返回 expect((await program.navigateBack()).path).toBe('pages/tabBar/component/component') }) })