diff --git a/pages/reactivity/core/watch-post-effect/watch-post-effect.test.js b/pages/reactivity/core/watch-post-effect/watch-post-effect.test.js index f31b02776f27d12355c542330b0fb27a7c6c287f..915311805c17f3711c1f5a5e2e04298b3df2e152 100644 --- a/pages/reactivity/core/watch-post-effect/watch-post-effect.test.js +++ b/pages/reactivity/core/watch-post-effect/watch-post-effect.test.js @@ -6,7 +6,7 @@ describe('watchPostEffect', () => { const isAndroid = platformInfo.startsWith('android') const isIos = platformInfo.startsWith('ios') const isWeb = platformInfo.startsWith('web') - + beforeAll(async () => { page = await program.reLaunch(PAGE_PATH) await page.waitFor('view') @@ -113,16 +113,8 @@ describe('watchPostEffect', () => { expect(await objArr.text()).toBe('[0]') const watchObjRes = await page.$('#watch-obj-res') - // TODO web端和安å“端JSON.stringify对属性的排åºä¸ä¸€è‡´ - if (process.env.uniTestPlatformInfo.startsWith('web') || isIos) { - expect(await watchObjRes.text()).toBe( - 'obj: {"num":0,"str":"num: 0","bool":false,"arr":[0]}' - ) - } else { - expect(await watchObjRes.text()).toBe( - 'obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}' - ) - } + expect(await watchObjRes.text()).toBe('obj: {"num":0,"str":"num: 0","bool":false,"arr":[0]}') + const watchObjStrRes = await page.$('#watch-obj-str-res') expect(await watchObjStrRes.text()).toBe( 'str: num: 0, obj.str ref text: num: 0') @@ -142,15 +134,7 @@ describe('watchPostEffect', () => { expect(await objBool.text()).toBe('true') expect(await objArr.text()).toBe('[0,1]') - if (process.env.uniTestPlatformInfo.startsWith('web') || isIos) { - expect(await watchObjRes.text()).toBe( - 'obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}' - ) - } else { - expect(await watchObjRes.text()).toBe( - 'obj: {"arr":[0,1],"bool":true,"num":1,"str":"num: 1"}' - ) - } + expect(await watchObjRes.text()).toBe('obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}') expect(await watchObjStrRes.text()).toBe( 'str: num: 1, obj.str ref text: num: 1') diff --git a/pages/reactivity/core/watch-post-effect/watch-post-effect.uvue b/pages/reactivity/core/watch-post-effect/watch-post-effect.uvue index b63bc451610b252944fec544e354b751c8e3df74..7d9cbbd2c238c61d583b52e432c021e00eb6965a 100644 --- a/pages/reactivity/core/watch-post-effect/watch-post-effect.uvue +++ b/pages/reactivity/core/watch-post-effect/watch-post-effect.uvue @@ -127,7 +127,7 @@ const watchObjRes = ref('') watchPostEffect(() => { - watchObjRes.value = `obj: ${JSON.stringify(obj)}` + watchObjRes.value = `obj: {"num":${obj.num},"str":"${obj.str}","bool":${obj.bool},"arr":${JSON.stringify(obj.arr)}}` }) const objStrRef = ref<UniTextElement | null>(null) diff --git a/pages/reactivity/core/watch-sync-effect/watch-sync-effect.test.js b/pages/reactivity/core/watch-sync-effect/watch-sync-effect.test.js index 09bda0065f609a72c07e93937ed3ce3b2ca61b1b..4605ad96a8196d36a5557a29f70a68fd8f1a67cb 100644 --- a/pages/reactivity/core/watch-sync-effect/watch-sync-effect.test.js +++ b/pages/reactivity/core/watch-sync-effect/watch-sync-effect.test.js @@ -6,7 +6,7 @@ describe('watchSyncEffect', () => { const isAndroid = platformInfo.startsWith('android') const isIos = platformInfo.startsWith('ios') const isWeb = platformInfo.startsWith('web') - + beforeAll(async () => { page = await program.reLaunch(PAGE_PATH) await page.waitFor('view') @@ -111,15 +111,7 @@ describe('watchSyncEffect', () => { expect(await objArr.text()).toBe('[0]') const watchObjRes = await page.$('#watch-obj-res') - if (isWeb || isIos) { - expect(await watchObjRes.text()).toBe( - 'obj: {"num":0,"str":"num: 0","bool":false,"arr":[0]}' - ) - } else { - expect(await watchObjRes.text()).toBe( - 'obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}' - ) - } + expect(await watchObjRes.text()).toBe('obj: {"num":0,"str":"num: 0","bool":false,"arr":[0]}') const watchObjStrRes = await page.$('#watch-obj-str-res') expect(await watchObjStrRes.text()).toBe( @@ -140,15 +132,7 @@ describe('watchSyncEffect', () => { expect(await objBool.text()).toBe('true') expect(await objArr.text()).toBe('[0,1]') - if (isWeb || isIos) { - expect(await watchObjRes.text()).toBe( - 'obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}' - ) - } else { - expect(await watchObjRes.text()).toBe( - 'obj: {"arr":[0,1],"bool":true,"num":1,"str":"num: 1"}' - ) - } + expect(await watchObjRes.text()).toBe('obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}') expect(await watchObjStrRes.text()).toBe( 'str: num: 1, obj.str ref text: num: 0') diff --git a/pages/reactivity/core/watch-sync-effect/watch-sync-effect.uvue b/pages/reactivity/core/watch-sync-effect/watch-sync-effect.uvue index 88d2fd0d15a1ec04824c07dad7b6a1b1cb4aaf45..7c21482f696dce93581f651ab9b99054b73ad9f0 100644 --- a/pages/reactivity/core/watch-sync-effect/watch-sync-effect.uvue +++ b/pages/reactivity/core/watch-sync-effect/watch-sync-effect.uvue @@ -127,7 +127,7 @@ const watchObjRes = ref('') watchSyncEffect(() => { - watchObjRes.value = `obj: ${JSON.stringify(obj)}` + watchObjRes.value = `obj: {"num":${obj.num},"str":"${obj.str}","bool":${obj.bool},"arr":${JSON.stringify(obj.arr)}}` }) const objStrRef = ref<UniTextElement | null>(null) diff --git a/pages/reactivity/core/watch/watch-options.test.js b/pages/reactivity/core/watch/watch-options.test.js index 99969ef61c19aa6403436ef9e699e97fc777c80b..49be8cbeabc10d56b317d2489fc82cbbf7452ffa 100644 --- a/pages/reactivity/core/watch/watch-options.test.js +++ b/pages/reactivity/core/watch/watch-options.test.js @@ -36,7 +36,7 @@ describe('watch', () => { expect(await count.text()).toBe('1') expect(await watchCountRes.text()).toBe( - 'count: 1, prevCount: 0, count ref text (flush sync): 0') + `count: 1, prevCount: 0, count ref text (flush sync): ${isWeb? 'null': '0'}`) if (isAndroid) { expect(await watchCountTrackNum.text()).toBe('1') @@ -49,12 +49,13 @@ describe('watch', () => { await incrementBtn.tap() expect(await count.text()).toBe('2') - expect(await watchCountRes.text()).toBe('count: 2, prevCount: 1, count ref text (flush sync): 1') + expect(await watchCountRes.text()).toBe( + `count: 2, prevCount: 1, count ref text (flush sync): ${isWeb?'null': '1'}`) if (isAndroid) { expect(await watchCountTrackNum.text()).toBe('1') } - + if (isIos || isWeb) { expect(await watchCountTrackNum.text()).toBe('3') } @@ -74,12 +75,12 @@ describe('watch', () => { await incrementBtn.tap() expect(await count.text()).toBe('3') - + if (isApp) { expect(await watchCountRes.text()).toBe('count: 3, prevCount: 2, count ref text (flush sync): 2') } if (isWeb) { - expect(await watchCountRes.text()).toBe('count: 2, prevCount: 1, count ref text (flush sync): 1') + expect(await watchCountRes.text()).toBe('count: 2, prevCount: 1, count ref text (flush sync): null') } if (isAndroid) { @@ -91,7 +92,7 @@ describe('watch', () => { if (isWeb) { expect(await watchCountTrackNum.text()).toBe('3') } - + expect(await watchCountCleanupRes.text()).toBe('watch count cleanup: 2') }) @@ -108,7 +109,7 @@ describe('watch', () => { const watchObjRes = await page.$('#watch-obj-res') if (isAndroid) { expect(await watchObjRes.text()).toBe( - 'obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}, prevObj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}' + 'obj: {"num":0,"str":"num: 0","bool":false,"arr":[0]}, prevObj: {"num":0,"str":"num: 0","bool":false,"arr":[0]}' ) } if (isIos || isWeb) { @@ -136,23 +137,17 @@ describe('watch', () => { expect(await objBool.text()).toBe('true') expect(await objArr.text()).toBe('[0,1]') - if (isAndroid) { - expect(await watchObjRes.text()).toBe( - 'obj: {"arr":[0,1],"bool":true,"num":1,"str":"num: 1"}, prevObj: {"arr":[0,1],"bool":true,"num":1,"str":"num: 1"}' - ) - } - if (isIos || isWeb) { - expect(await watchObjRes.text()).toBe( - 'obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}, prevObj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}' - ) - } + + expect(await watchObjRes.text()).toBe( + 'obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}, prevObj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}' + ) expect(await watchObjStrRes.text()).toBe( - 'str: num: 1, prevStr: num: 0, obj.str ref text (flush pre): num: 0') + `str: num: 1, prevStr: num: 0, obj.str ref text (flush pre): ${isWeb?'null': 'num: 0'}`) expect(await watchObjStrTriggerNum.text()).toBe('0') expect(await watchObjBoolRes.text()).toBe( - 'bool: true, prevBool: false, obj.bool ref text (flush post): true' + `bool: true, prevBool: false, obj.bool ref text (flush post): ${isWeb?'null':'true'}` ) expect(await watchObjArrRes.text()).toBe('arr: [0,1], prevArr: [0,1]') }) diff --git a/pages/reactivity/core/watch/watch-options.uvue b/pages/reactivity/core/watch/watch-options.uvue index 9bb77d784d9aa93ac2a6e93dcd0975ae44bbbfa0..2caa7dd9d02ac952775ec862af4aab4c3c65a55a 100644 --- a/pages/reactivity/core/watch/watch-options.uvue +++ b/pages/reactivity/core/watch/watch-options.uvue @@ -156,7 +156,11 @@ watch: { obj: { handler(obj : Obj, prevObj ?: Obj) { - this.watchObjRes = `obj: ${JSON.stringify(obj)}, prevObj: ${JSON.stringify(prevObj)}` + if (prevObj === null) { + this.watchObjRes = `obj: {"num":${obj.num},"str":"${obj.str}","bool":${obj.bool},"arr":${JSON.stringify(obj.arr)}}, prevObj: ${JSON.stringify(prevObj)}` + } else { + this.watchObjRes = `obj: {"num":${obj.num},"str":"${obj.str}","bool":${obj.bool},"arr":${JSON.stringify(obj.arr)}}, prevObj: {"num":${prevObj?.num},"str":"${prevObj?.str}","bool":${prevObj?.bool},"arr":${JSON.stringify(prevObj?.arr)}}` + } }, // immediate: true 第一次触å‘, 旧值应该是 undefined, 现在 app 是åˆå§‹å€¼ immediate: true,