提交 f724a150 编写于 作者: 辛宝Otto's avatar 辛宝Otto 🥊

test: 兼容不同平台的字段排序差异

上级 6b4c1923
...@@ -106,16 +106,21 @@ describe('watchPostEffect', () => { ...@@ -106,16 +106,21 @@ describe('watchPostEffect', () => {
expect(await objArr.text()).toBe('obj.arr: [0]') expect(await objArr.text()).toBe('obj.arr: [0]')
const watchObjRes = await page.$('#watch-obj-res') const watchObjRes = await page.$('#watch-obj-res')
// TODO web端和安卓端JSON.stringify对属性的排序不一致 // web端和安卓端JSON.stringify对属性的排序不一致
if (process.env.uniTestPlatformInfo.startsWith('web') || process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) { // 该用字符串特征判断和字符串 JSON 解析
expect(await watchObjRes.text()).toBe( const watchObjRestRaw = await watchObjRes.text()
'watch obj result: obj: {"num":0,"str":"num: 0","bool":false,"arr":[0]}'
) expect(watchObjRestRaw.startsWith('watch obj result: obj:')).toBe(true)
} else { const stringJSON = watchObjRestRaw.split('watch obj result: obj:')
expect(await watchObjRes.text()).toBe( expect(Array.isArray(stringJSON)).toBe(true)
'watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}' expect(stringJSON.length).toBe(2)
) expect(JSON.parse(stringJSON[1])).toEqual({
} "num": 0,
"str": "num: 0",
"bool": false,
"arr": [0]
})
const watchObjStrRes = await page.$('#watch-obj-str-res') const watchObjStrRes = await page.$('#watch-obj-str-res')
expect(await watchObjStrRes.text()).toBe( expect(await watchObjStrRes.text()).toBe(
'watch obj.str result: str: num: 0, obj.str ref text: obj.str: num: 0') 'watch obj.str result: str: num: 0, obj.str ref text: obj.str: num: 0')
...@@ -135,15 +140,19 @@ describe('watchPostEffect', () => { ...@@ -135,15 +140,19 @@ describe('watchPostEffect', () => {
expect(await objBool.text()).toBe('obj.bool: true') expect(await objBool.text()).toBe('obj.bool: true')
expect(await objArr.text()).toBe('obj.arr: [0,1]') expect(await objArr.text()).toBe('obj.arr: [0,1]')
if (process.env.uniTestPlatformInfo.startsWith('web') || process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) { const watchObjRestRaw2 = await watchObjRes.text()
expect(await watchObjRes.text()).toBe( expect(watchObjRestRaw2.startsWith('watch obj result: obj:')).toBe(true)
'watch obj result: obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}' const stringJSON2 = watchObjRestRaw2.split('watch obj result: obj:')
) expect(Array.isArray(stringJSON2)).toBe(true)
} else { expect(stringJSON2.length).toBe(2)
expect(await watchObjRes.text()).toBe( expect(JSON.parse(stringJSON2[1])).toEqual({
'watch obj result: obj: {"arr":[0,1],"bool":true,"num":1,"str":"num: 1"}' "num": 1,
) "str": "num: 1",
} "bool": true,
"arr": [0, 1]
})
expect(await watchObjStrRes.text()).toBe( expect(await watchObjStrRes.text()).toBe(
'watch obj.str result: str: num: 1, obj.str ref text: obj.str: num: 1') 'watch obj.str result: str: num: 1, obj.str ref text: obj.str: num: 1')
......
const PAGE_PATH = '/pages/composition-api/reactivity/watch-sync-effect/watch-sync-effect' const PAGE_PATH = '/pages/composition-api/reactivity/watch-sync-effect/watch-sync-effect'
// 15.5 复测ok 16.4ok 17ok
describe('watchSyncEffect', () => { describe('watchSyncEffect', () => {
let page = null let page = null
beforeAll(async () => { beforeAll(async () => {
...@@ -106,15 +107,20 @@ describe('watchSyncEffect', () => { ...@@ -106,15 +107,20 @@ describe('watchSyncEffect', () => {
expect(await objArr.text()).toBe('obj.arr: [0]') expect(await objArr.text()).toBe('obj.arr: [0]')
const watchObjRes = await page.$('#watch-obj-res') const watchObjRes = await page.$('#watch-obj-res')
if (process.env.uniTestPlatformInfo.startsWith('web') || process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) {
expect(await watchObjRes.text()).toBe( // web端和安卓端JSON.stringify对属性的排序不一致
'watch obj result: obj: {"num":0,"str":"num: 0","bool":false,"arr":[0]}' // 该用字符串特征判断和字符串 JSON 解析
) const watchObjRestRaw = await watchObjRes.text()
} else { expect(watchObjRestRaw.startsWith('watch obj result: obj:')).toBe(true)
expect(await watchObjRes.text()).toBe( const stringJSON = watchObjRestRaw.split('watch obj result: obj:')
'watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}' expect(Array.isArray(stringJSON)).toBe(true)
) expect(stringJSON.length).toBe(2)
} expect(JSON.parse(stringJSON[1])).toEqual({
"num": 0,
"str": "num: 0",
"bool": false,
"arr": [0]
})
const watchObjStrRes = await page.$('#watch-obj-str-res') const watchObjStrRes = await page.$('#watch-obj-str-res')
expect(await watchObjStrRes.text()).toBe( expect(await watchObjStrRes.text()).toBe(
...@@ -135,15 +141,17 @@ describe('watchSyncEffect', () => { ...@@ -135,15 +141,17 @@ describe('watchSyncEffect', () => {
expect(await objBool.text()).toBe('obj.bool: true') expect(await objBool.text()).toBe('obj.bool: true')
expect(await objArr.text()).toBe('obj.arr: [0,1]') expect(await objArr.text()).toBe('obj.arr: [0,1]')
if (process.env.uniTestPlatformInfo.startsWith('web') || process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) { const watchObjRestRaw2 = await watchObjRes.text()
expect(await watchObjRes.text()).toBe( expect(watchObjRestRaw2.startsWith('watch obj result: obj:')).toBe(true)
'watch obj result: obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}' const stringJSON2 = watchObjRestRaw2.split('watch obj result: obj:')
) expect(Array.isArray(stringJSON2)).toBe(true)
} else { expect(stringJSON2.length).toBe(2)
expect(await watchObjRes.text()).toBe( expect(JSON.parse(stringJSON2[1])).toEqual({
'watch obj result: obj: {"arr":[0,1],"bool":true,"num":1,"str":"num: 1"}' "num": 1,
) "str": "num: 1",
} "bool": true,
"arr": [0, 1]
})
expect(await watchObjStrRes.text()).toBe( expect(await watchObjStrRes.text()).toBe(
'watch obj.str result: str: num: 1, obj.str ref text: obj.str: num: 0') 'watch obj.str result: str: num: 1, obj.str ref text: obj.str: num: 0')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册