From ec78511fcfe98ad3901c9e48a4e1b3d6d8cc946e Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Tue, 28 Nov 2023 20:14:18 +0800 Subject: [PATCH] =?UTF-8?q?test(globalData):=20=E6=94=AF=E6=8C=81=20web=20?= =?UTF-8?q?=E7=AB=AF=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/API/get-app/get-app.test.js | 95 ++++++++++++++++--------------- 1 file changed, 50 insertions(+), 45 deletions(-) diff --git a/pages/API/get-app/get-app.test.js b/pages/API/get-app/get-app.test.js index c61dddaa..64f028f8 100644 --- a/pages/API/get-app/get-app.test.js +++ b/pages/API/get-app/get-app.test.js @@ -1,57 +1,62 @@ const PAGE_PATH = '/pages/API/get-app/get-app' describe('getApp', () => { - if (process.env.uniTestPlatformInfo.startsWith('android')) { - let page = null - beforeAll(async () => { - page = await program.navigateTo(PAGE_PATH) - await page.waitFor('view') + let page = null + beforeAll(async () => { + page = await program.navigateTo(PAGE_PATH) + await page.waitFor('view') + }) + it('globalData', async () => { + await page.callMethod('getGlobalData') + let data = await page.data() + expect(data.originGlobalData.str).toBe('default globalData str') + expect(data.originGlobalData.num).toBe(0) + expect(data.originGlobalData.bool).toBe(false) + expect(data.originGlobalData.obj).toEqual({ + bool: false, + num: 0, + str: 'default globalData obj str' }) - it('globalData', async () => { - await page.callMethod('getGlobalData') - let data = await page.data() - expect(data.originGlobalData.str).toBe('default globalData str') - expect(data.originGlobalData.num).toBe(0) - expect(data.originGlobalData.bool).toBe(false) - expect(data.originGlobalData.obj).toEqual({ - bool: false, - num: 0, - str: 'default globalData obj str' - }) - expect(data.originGlobalData.arr).toEqual([]) + expect(data.originGlobalData.arr).toEqual([]) + if (process.env.uniTestPlatformInfo.startsWith('android')) { expect(data.originGlobalData.set).toEqual([]) - expect(data.originGlobalData.map).toEqual({}) - expect(data.originGlobalDataFuncRes).toBe('globalData func') - await page.callMethod('setGlobalData') - data = await page.data() - expect(data.newGlobalData.str).toBe('new globalData str') - expect(data.newGlobalData.num).toBe(100) - expect(data.newGlobalData.bool).toBe(true) - expect(data.newGlobalData.obj).toEqual({ - bool: true, - num: 200, - str: 'new globalData obj str' - }) - expect(data.newGlobalData.arr).toEqual([1, 2, 3]) + } else { + expect(data.originGlobalData.set).toEqual({}) + } + expect(data.originGlobalData.map).toEqual({}) + expect(data.originGlobalDataFuncRes).toBe('globalData func') + await page.callMethod('setGlobalData') + data = await page.data() + expect(data.newGlobalData.str).toBe('new globalData str') + expect(data.newGlobalData.num).toBe(100) + expect(data.newGlobalData.bool).toBe(true) + expect(data.newGlobalData.obj).toEqual({ + bool: true, + num: 200, + str: 'new globalData obj str' + }) + expect(data.newGlobalData.arr).toEqual([1, 2, 3]) + if (process.env.uniTestPlatformInfo.startsWith('android')) { expect(data.newGlobalData.set).toEqual(['a', 'b', 'c']) + } else { + expect(data.originGlobalData.set).toEqual({}) + } + if (process.env.uniTestPlatformInfo.startsWith('android')) { expect(data.newGlobalData.map).toEqual({ 'a': 1, 'b': 2, 'c': 3 }) - expect(data.newGlobalDataFuncRes).toBe('new globalData func') - }) - it('method', async () => { - const oldLifeCycleNum = await page.data('lifeCycleNum') - await page.callMethod('_increasetLifeCycleNum') - const newLifeCycleNum = await page.data('lifeCycleNum') - expect(newLifeCycleNum - oldLifeCycleNum).toBe(100) - await page.callMethod('setLifeCycleNum', oldLifeCycleNum) - }) - } else { - // TODO: web 端暂不支持 - it('web', async () => { - expect(1).toBe(1) - }) - } + } else { + expect(data.originGlobalData.map).toEqual({}) + } + expect(data.newGlobalDataFuncRes).toBe('new globalData func') + }) + it('method', async () => { + const oldLifeCycleNum = await page.data('lifeCycleNum') + await page.callMethod('_increasetLifeCycleNum') + const newLifeCycleNum = await page.data('lifeCycleNum') + expect(newLifeCycleNum - oldLifeCycleNum).toBe(100) + await page.callMethod('setLifeCycleNum', oldLifeCycleNum) + }) }) \ No newline at end of file -- GitLab