From 3331cf0243b9c4e9a5c9cb82eaa542a15ae458d5 Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Thu, 23 Nov 2023 23:16:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20globalData=20=E8=A1=A5=E5=85=85?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.uvue | 24 +++-- pages/API/get-app/get-app.test.js | 23 +++-- pages/API/get-app/get-app.uvue | 162 +++++++++++++++++++++++++----- 3 files changed, 169 insertions(+), 40 deletions(-) diff --git a/App.uvue b/App.uvue index 91dd5ed9..ad633395 100644 --- a/App.uvue +++ b/App.uvue @@ -2,11 +2,23 @@ import { state, setLifeCycleNum } from '@/store/index.uts' let firstBackTime = 0 - export default { - globalData: { - str: 'global data str', - num: 123, - bool: true, + 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[], + set: new Set(), + map: new Map(), + func: (): string => { + return 'globalData func' + } }, onLaunch: function () { // 自动化测试 @@ -67,4 +79,4 @@ \ No newline at end of file + diff --git a/pages/API/get-app/get-app.test.js b/pages/API/get-app/get-app.test.js index 4d229d7e..8d01b33e 100644 --- a/pages/API/get-app/get-app.test.js +++ b/pages/API/get-app/get-app.test.js @@ -9,15 +9,24 @@ describe('getApp', () => { it('globalData', async () => { await page.callMethod('getGlobalData') let data = await page.data() - expect(data.globalDataStr).toBe('global data str') - expect(data.globalDataNum).toBe(123) - expect(data.globalDataBool).toBe(true) + 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.set).toEqual([]) + expect(data.originGlobalData.map).toEqual({}) + expect(data.originGlobalDataFuncRes).toBe('globalData func') await page.callMethod('setGlobalData') - await page.callMethod('getGlobalData') data = await page.data() - expect(data.globalDataStr).toBe('new global data str') - expect(data.globalDataNum).toBe(456) - expect(data.globalDataBool).toBe(false) + 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.set).toEqual(['a', 'b', 'c']) + 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') diff --git a/pages/API/get-app/get-app.uvue b/pages/API/get-app/get-app.uvue index 3b8365db..f3bc1dd7 100644 --- a/pages/API/get-app/get-app.uvue +++ b/pages/API/get-app/get-app.uvue @@ -1,33 +1,99 @@ + + + -- GitLab