diff --git a/App.uvue b/App.uvue index f1aa02c9c53bb99869e5ec15c6dae670e0715d63..5db4455497b6a5b845473c571e8f24ba0f29d349 100644 --- a/App.uvue +++ b/App.uvue @@ -3,6 +3,23 @@ let firstBackTime = 0 export default { + globalData: { + str: 'default globalData str', + num: 0, + bool: false, + obj: { + str: 'default globalData obj str', + num: 0, + bool: false, + }, + null: null as string | null, + arr: [] as number[], + mySet: new Set(), + myMap: new Map(), + func: () : string => { + return 'globalData func' + } + }, onLaunch: function () { // 自动化测试 setLifeCycleNum(state.lifeCycleNum + 1000) diff --git a/pages/API/get-app/get-app.test.js b/pages/API/get-app/get-app.test.js index 5ede34d4fa16c9da4a210797fd75d28c10e0b11d..598a639b7f93ee90d14b3880fbb16067f0f72ab2 100644 --- a/pages/API/get-app/get-app.test.js +++ b/pages/API/get-app/get-app.test.js @@ -6,6 +6,40 @@ describe('getApp', () => { 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', + }) + expect(data.originGlobalData.arr).toEqual([]) + expect(data.originGlobalData.mySet).toEqual([]) + expect(data.originGlobalData.myMap).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]) + expect(data.newGlobalData.mySet).toEqual(['a', 'b', 'c']) + expect(data.newGlobalData.myMap).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') @@ -13,4 +47,4 @@ describe('getApp', () => { expect(newLifeCycleNum - oldLifeCycleNum).toBe(100) await page.callMethod('setLifeCycleNum', oldLifeCycleNum) }) -}) +}) diff --git a/pages/API/get-app/get-app.uvue b/pages/API/get-app/get-app.uvue index aaf5fa1a0c171c6aac82ea71ca282a6b9e12e2c9..dbea3b1dd43992704705cdfaf725889f38871e94 100644 --- a/pages/API/get-app/get-app.uvue +++ b/pages/API/get-app/get-app.uvue @@ -5,6 +5,32 @@ + + + + 点击按钮调用 App.uvue methods increasetLifeCycleNum 方法