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

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

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