提交 7ba0173b 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

test: 调整 app 实例示例及测试

上级 c3066529
...@@ -8,21 +8,17 @@ describe('getApp', () => { ...@@ -8,21 +8,17 @@ describe('getApp', () => {
}) })
it('globalData', async () => { it('globalData', async () => {
await page.callMethod('getGlobalData') await page.callMethod('getGlobalData')
let data = await page.data() let data = await page.data()
expect(data.originGlobalData.str).toBe('default globalData str') expect(data.originGlobalData.str).toBe('default globalData str')
expect(data.originGlobalData.num).toBe(0) expect(data.originGlobalData.num).toBe(0)
expect(data.originGlobalData.bool).toBe(false) expect(data.originGlobalData.bool).toBe(false)
expect(data.originGlobalData.obj).toEqual({ expect(data.originGlobalData.obj).toEqual({
bool: false, bool: false,
num: 0, num: 0,
str: 'default globalData obj str' str: 'default globalData obj str',
}) })
expect(data.originGlobalData.arr).toEqual([]) expect(data.originGlobalData.arr).toEqual([])
if (process.env.uniTestPlatformInfo.startsWith('android')) { expect(data.originGlobalData.mySet).toEqual([])
expect(data.originGlobalData.mySet).toEqual([])
} else {
expect(data.originGlobalData.mySet).toEqual({})
}
expect(data.originGlobalData.myMap).toEqual({}) expect(data.originGlobalData.myMap).toEqual({})
expect(data.originGlobalDataFuncRes).toBe('globalData func') expect(data.originGlobalDataFuncRes).toBe('globalData func')
await page.callMethod('setGlobalData') await page.callMethod('setGlobalData')
...@@ -33,23 +29,11 @@ describe('getApp', () => { ...@@ -33,23 +29,11 @@ describe('getApp', () => {
expect(data.newGlobalData.obj).toEqual({ expect(data.newGlobalData.obj).toEqual({
bool: true, bool: true,
num: 200, num: 200,
str: 'new globalData obj str' str: 'new globalData obj str',
}) })
expect(data.newGlobalData.arr).toEqual([1, 2, 3]) expect(data.newGlobalData.arr).toEqual([1, 2, 3])
if (process.env.uniTestPlatformInfo.startsWith('android')) { expect(data.newGlobalData.mySet).toEqual(['a', 'b', 'c'])
expect(data.newGlobalData.mySet).toEqual(['a', 'b', 'c']) expect(data.newGlobalData.myMap).toEqual({a: 1, b: 2, c: 3})
} else {
expect(data.originGlobalData.mySet).toEqual({})
}
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(data.newGlobalData.myMap).toEqual({
'a': 1,
'b': 2,
'c': 3
})
} else {
expect(data.originGlobalData.myMap).toEqual({})
}
expect(data.newGlobalDataFuncRes).toBe('new globalData func') expect(data.newGlobalDataFuncRes).toBe('new globalData func')
}) })
it('method', async () => { it('method', async () => {
...@@ -59,4 +43,4 @@ describe('getApp', () => { ...@@ -59,4 +43,4 @@ describe('getApp', () => {
expect(newLifeCycleNum - oldLifeCycleNum).toBe(100) expect(newLifeCycleNum - oldLifeCycleNum).toBe(100)
await page.callMethod('setLifeCycleNum', oldLifeCycleNum) await page.callMethod('setLifeCycleNum', oldLifeCycleNum)
}) })
}) })
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<text class="uni-common-mt">globalData Map: {{ originGlobalData.myMap }}</text> <text class="uni-common-mt">globalData Map: {{ originGlobalData.myMap }}</text>
<text class="uni-common-mt">globalData func 返回值: {{ originGlobalDataFuncRes }}</text> <text class="uni-common-mt">globalData func 返回值: {{ originGlobalDataFuncRes }}</text>
</template> </template>
<button @click="setGlobalData" class="uni-common-mt">mySet globalData</button> <button @click="setGlobalData" class="uni-common-mt">set globalData</button>
<template v-if="newGlobalData.bool"> <template v-if="newGlobalData.bool">
<text class="uni-common-mt bold">更新后的 globalData:</text> <text class="uni-common-mt bold">更新后的 globalData:</text>
<text class="uni-common-mt">globalData string: {{ newGlobalData.str }}</text> <text class="uni-common-mt">globalData string: {{ newGlobalData.str }}</text>
...@@ -53,8 +53,8 @@ ...@@ -53,8 +53,8 @@
obj : UTSJSONObject, obj : UTSJSONObject,
null : string | null, null : string | null,
arr : number[], arr : number[],
mySet : Set<string>, mySet : string[],
myMap : Map<string, any>, myMap : UTSJSONObject,
func : () => string func : () => string
} }
import { state, setLifeCycleNum } from '@/store/index.uts' import { state, setLifeCycleNum } from '@/store/index.uts'
...@@ -73,8 +73,8 @@ ...@@ -73,8 +73,8 @@
} as UTSJSONObject, } as UTSJSONObject,
null: null, null: null,
arr: [] as number[], arr: [] as number[],
mySet: new Set<string>(), mySet: [] as string[],
myMap: new Map<string, any>(), myMap: {},
func: () : string => '' func: () : string => ''
} as MyGlobalData, } as MyGlobalData,
originGlobalDataFuncRes: '', originGlobalDataFuncRes: '',
...@@ -89,8 +89,8 @@ ...@@ -89,8 +89,8 @@
} as UTSJSONObject, } as UTSJSONObject,
null: null, null: null,
arr: [] as number[], arr: [] as number[],
mySet: new Set<string>(), mySet: [] as string[],
myMap: new Map<string, any>(), myMap: {},
func: () : string => '' func: () : string => ''
} as MyGlobalData, } as MyGlobalData,
newGlobalDataFuncRes: '', newGlobalDataFuncRes: '',
...@@ -108,9 +108,13 @@ ...@@ -108,9 +108,13 @@
this.originGlobalData.bool = app.globalData.bool this.originGlobalData.bool = app.globalData.bool
this.originGlobalData.obj = app.globalData.obj this.originGlobalData.obj = app.globalData.obj
this.originGlobalData.null = app.globalData.null this.originGlobalData.null = app.globalData.null
this.originGlobalData.arr = app.globalData.arr this.originGlobalData.arr = app.globalData.arr
this.originGlobalData.mySet = app.globalData.mySet app.globalData.mySet.forEach(value => {
this.originGlobalData.myMap = app.globalData.myMap this.originGlobalData.mySet.push(value)
})
app.globalData.myMap.forEach((value, key) => {
this.originGlobalData.myMap[key] = value
})
this.originGlobalData.func = app.globalData.func this.originGlobalData.func = app.globalData.func
this.originGlobalDataFuncRes = this.originGlobalData.func() this.originGlobalDataFuncRes = this.originGlobalData.func()
}, },
...@@ -143,8 +147,12 @@ ...@@ -143,8 +147,12 @@
this.newGlobalData.obj = app.globalData.obj this.newGlobalData.obj = app.globalData.obj
this.newGlobalData.null = app.globalData.null this.newGlobalData.null = app.globalData.null
this.newGlobalData.arr = app.globalData.arr this.newGlobalData.arr = app.globalData.arr
this.newGlobalData.mySet = app.globalData.mySet app.globalData.mySet.forEach(value => {
this.newGlobalData.myMap = app.globalData.myMap this.newGlobalData.mySet.push(value)
})
app.globalData.myMap.forEach((value, key) => {
this.newGlobalData.myMap[key] = value
})
this.newGlobalData.func = app.globalData.func this.newGlobalData.func = app.globalData.func
this.newGlobalDataFuncRes = this.newGlobalData.func() this.newGlobalDataFuncRes = this.newGlobalData.func()
}, },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册