From f724a150d7f92718345d76c62e6d4a9a2cd73a7f Mon Sep 17 00:00:00 2001 From: jixinbao Date: Sun, 28 Apr 2024 15:31:33 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E5=85=BC=E5=AE=B9=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E7=9A=84=E5=AD=97=E6=AE=B5=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E5=B7=AE=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../watch-post-effect.test.js | 47 +++++++++++-------- .../watch-sync-effect.test.js | 44 ++++++++++------- 2 files changed, 54 insertions(+), 37 deletions(-) diff --git a/pages/composition-api/reactivity/watch-post-effect/watch-post-effect.test.js b/pages/composition-api/reactivity/watch-post-effect/watch-post-effect.test.js index db152f5..6507313 100644 --- a/pages/composition-api/reactivity/watch-post-effect/watch-post-effect.test.js +++ b/pages/composition-api/reactivity/watch-post-effect/watch-post-effect.test.js @@ -106,16 +106,21 @@ describe('watchPostEffect', () => { expect(await objArr.text()).toBe('obj.arr: [0]') const watchObjRes = await page.$('#watch-obj-res') - // TODO web端和安卓端JSON.stringify对属性的排序不一致 - if (process.env.uniTestPlatformInfo.startsWith('web') || process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) { - expect(await watchObjRes.text()).toBe( - 'watch obj result: obj: {"num":0,"str":"num: 0","bool":false,"arr":[0]}' - ) - } else { - expect(await watchObjRes.text()).toBe( - 'watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}' - ) - } + // web端和安卓端JSON.stringify对属性的排序不一致 + // 该用字符串特征判断和字符串 JSON 解析 + const watchObjRestRaw = await watchObjRes.text() + + expect(watchObjRestRaw.startsWith('watch obj result: obj:')).toBe(true) + const stringJSON = watchObjRestRaw.split('watch obj result: obj:') + 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') expect(await watchObjStrRes.text()).toBe( 'watch obj.str result: str: num: 0, obj.str ref text: obj.str: num: 0') @@ -135,15 +140,19 @@ describe('watchPostEffect', () => { expect(await objBool.text()).toBe('obj.bool: true') expect(await objArr.text()).toBe('obj.arr: [0,1]') - if (process.env.uniTestPlatformInfo.startsWith('web') || process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) { - expect(await watchObjRes.text()).toBe( - 'watch obj result: obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}' - ) - } else { - expect(await watchObjRes.text()).toBe( - 'watch obj result: obj: {"arr":[0,1],"bool":true,"num":1,"str":"num: 1"}' - ) - } + const watchObjRestRaw2 = await watchObjRes.text() + expect(watchObjRestRaw2.startsWith('watch obj result: obj:')).toBe(true) + const stringJSON2 = watchObjRestRaw2.split('watch obj result: obj:') + expect(Array.isArray(stringJSON2)).toBe(true) + expect(stringJSON2.length).toBe(2) + expect(JSON.parse(stringJSON2[1])).toEqual({ + "num": 1, + "str": "num: 1", + "bool": true, + "arr": [0, 1] + }) + + expect(await watchObjStrRes.text()).toBe( 'watch obj.str result: str: num: 1, obj.str ref text: obj.str: num: 1') diff --git a/pages/composition-api/reactivity/watch-sync-effect/watch-sync-effect.test.js b/pages/composition-api/reactivity/watch-sync-effect/watch-sync-effect.test.js index dc0673c..d7f2179 100644 --- a/pages/composition-api/reactivity/watch-sync-effect/watch-sync-effect.test.js +++ b/pages/composition-api/reactivity/watch-sync-effect/watch-sync-effect.test.js @@ -1,5 +1,6 @@ const PAGE_PATH = '/pages/composition-api/reactivity/watch-sync-effect/watch-sync-effect' +// 15.5 复测ok 16.4ok 17ok describe('watchSyncEffect', () => { let page = null beforeAll(async () => { @@ -106,15 +107,20 @@ describe('watchSyncEffect', () => { expect(await objArr.text()).toBe('obj.arr: [0]') const watchObjRes = await page.$('#watch-obj-res') - if (process.env.uniTestPlatformInfo.startsWith('web') || process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) { - expect(await watchObjRes.text()).toBe( - 'watch obj result: obj: {"num":0,"str":"num: 0","bool":false,"arr":[0]}' - ) - } else { - expect(await watchObjRes.text()).toBe( - 'watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}' - ) - } + + // web端和安卓端JSON.stringify对属性的排序不一致 + // 该用字符串特征判断和字符串 JSON 解析 + const watchObjRestRaw = await watchObjRes.text() + expect(watchObjRestRaw.startsWith('watch obj result: obj:')).toBe(true) + const stringJSON = watchObjRestRaw.split('watch obj result: obj:') + 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') expect(await watchObjStrRes.text()).toBe( @@ -135,15 +141,17 @@ describe('watchSyncEffect', () => { expect(await objBool.text()).toBe('obj.bool: true') expect(await objArr.text()).toBe('obj.arr: [0,1]') - if (process.env.uniTestPlatformInfo.startsWith('web') || process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) { - expect(await watchObjRes.text()).toBe( - 'watch obj result: obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}' - ) - } else { - expect(await watchObjRes.text()).toBe( - 'watch obj result: obj: {"arr":[0,1],"bool":true,"num":1,"str":"num: 1"}' - ) - } + const watchObjRestRaw2 = await watchObjRes.text() + expect(watchObjRestRaw2.startsWith('watch obj result: obj:')).toBe(true) + const stringJSON2 = watchObjRestRaw2.split('watch obj result: obj:') + expect(Array.isArray(stringJSON2)).toBe(true) + expect(stringJSON2.length).toBe(2) + expect(JSON.parse(stringJSON2[1])).toEqual({ + "num": 1, + "str": "num: 1", + "bool": true, + "arr": [0, 1] + }) expect(await watchObjStrRes.text()).toBe( 'watch obj.str result: str: num: 1, obj.str ref text: obj.str: num: 0') -- GitLab