From 8c1900b9e7faba993ad6274a7fe96c00b78e8a4b Mon Sep 17 00:00:00 2001 From: wangjinxin613 <1749574663@qq.com> Date: Thu, 25 Jan 2024 17:42:58 +0800 Subject: [PATCH] =?UTF-8?q?test(watch-effect)=EF=BC=9A=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B=E5=85=BC=E5=AE=B9=20safari?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../watch-effect/watch-effect.test.js | 253 +++++++++--------- 1 file changed, 127 insertions(+), 126 deletions(-) diff --git a/pages/composition-api/reactivity/watch-effect/watch-effect.test.js b/pages/composition-api/reactivity/watch-effect/watch-effect.test.js index 661f989..e9c4a49 100644 --- a/pages/composition-api/reactivity/watch-effect/watch-effect.test.js +++ b/pages/composition-api/reactivity/watch-effect/watch-effect.test.js @@ -1,127 +1,128 @@ -const PAGE_PATH = '/pages/composition-api/reactivity/watch-effect/watch-effect' - -describe('watchEffect', () => { - let page = null - beforeAll(async () => { - page = await program.reLaunch(PAGE_PATH) - await page.waitFor('view') - }) - it('count', async () => { - const count = await page.$('#count') - expect(await count.text()).toBe('count: 0') - - // watch - const watchCountRes = await page.$('#watch-count-res') - expect(await watchCountRes.text()).toBe( - 'watch count result: count: 0, count ref text (flush sync): count: 0') - // track - const watchCountTrackNum = await page.$('#watch-count-track-num') - expect(await watchCountTrackNum.text()).toBe('watch count track number: 3') - - // trigger - const watchCountTriggerNum = await page.$('#watch-count-trigger-num') - expect(await watchCountTriggerNum.text()).toBe('watch count trigger number: 1') - const watchCountCleanupRes = await page.$('#watch-count-cleanup-res') - expect(await watchCountCleanupRes.text()).toBe('watch count cleanup result: watch count cleanup: 0') - - // watch count and obj.num - const watchCountAndObjNumRes = await page.$('#watch-count-obj-num-res') - expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: count: 0, obj.num: 0') - - const incrementBtn = await page.$('.increment-btn') - await incrementBtn.tap() - - expect(await count.text()).toBe('count: 1') - expect(await watchCountRes.text()).toBe( - 'watch count result: count: 1, count ref text (flush sync): count: 0') - expect(await watchCountTrackNum.text()).toBe('watch count track number: 3') - expect(await watchCountTriggerNum.text()).toBe('watch count trigger number: 2') - expect(await watchCountCleanupRes.text()).toBe('watch count cleanup result: watch count cleanup: 1') - - expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: count: 1, obj.num: 0') - - await incrementBtn.tap() - - expect(await count.text()).toBe('count: 2') - expect(await watchCountRes.text()).toBe( - 'watch count result: count: 2, count ref text (flush sync): count: 1') - - expect(await watchCountTrackNum.text()).toBe('watch count track number: 3') - expect(await watchCountTriggerNum.text()).toBe('watch count trigger number: 3') - expect(await watchCountCleanupRes.text()).toBe('watch count cleanup result: watch count cleanup: 2') - - expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: count: 2, obj.num: 0') - - // stop watch - const stopWatchCountBtn = await page.$('.stop-watch-count-btn') - await stopWatchCountBtn.tap() - - await incrementBtn.tap() - - expect(await count.text()).toBe('count: 3') - expect(await watchCountRes.text()).toBe( - 'watch count result: count: 2, count ref text (flush sync): count: 1') - - expect(await watchCountTrackNum.text()).toBe('watch count track number: 3') - expect(await watchCountTriggerNum.text()).toBe('watch count trigger number: 3') - expect(await watchCountCleanupRes.text()).toBe('watch count cleanup result: watch count cleanup: 2') - - expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: count: 3, obj.num: 0') - }) - it('obj', async () => { - const objStr = await page.$('#obj-str') - expect(await objStr.text()).toBe('obj.str: num: 0') - const objNum = await page.$('#obj-num') - expect(await objNum.text()).toBe('obj.num: 0') - const objBool = await page.$('#obj-bool') - expect(await objBool.text()).toBe('obj.bool: false') - const objArr = await page.$('#obj-arr') - expect(await objArr.text()).toBe('obj.arr: [0]') - - const watchObjRes = await page.$('#watch-obj-res') - if (process.env.uniTestPlatformInfo.startsWith('android')) { - expect(await watchObjRes.text()).toBe( - 'watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}') - } - if (process.env.uniTestPlatformInfo.startsWith('web')) { - expect(await watchObjRes.text()).toBe( - 'watch obj result: obj: {"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 (flush pre): obj.str: num: 0') - - const watchObjBoolRes = await page.$('#watch-obj-bool-res') - expect(await watchObjBoolRes.text()).toBe( - 'watch obj.bool result: bool: false, obj.bool ref text (flush post): obj.bool: false') - - const watchObjArrRes = await page.$('#watch-obj-arr-res') - expect(await watchObjArrRes.text()).toBe('watch obj.arr result: arr: [0]') - - const updateObjBtn = await page.$('.update-obj-btn') - await updateObjBtn.tap() - - expect(await objStr.text()).toBe('obj.str: num: 1') - expect(await objNum.text()).toBe('obj.num: 1') - expect(await objBool.text()).toBe('obj.bool: true') - expect(await objArr.text()).toBe('obj.arr: [0,1]') - - if (process.env.uniTestPlatformInfo.startsWith('android')) { - expect(await watchObjRes.text()).toBe( - 'watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}') - } - if (process.env.uniTestPlatformInfo.startsWith('web')) { - expect(await watchObjRes.text()).toBe( - 'watch obj result: obj: {"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 (flush pre): obj.str: num: 0') - expect(await watchObjBoolRes.text()).toBe( - 'watch obj.bool result: bool: true, obj.bool ref text (flush post): obj.bool: true') - - expect(await watchObjArrRes.text()).toBe('watch obj.arr result: arr: [0,1]') - - const watchCountAndObjNumRes = await page.$('#watch-count-obj-num-res') - expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: count: 3, obj.num: 1') - }) +const PAGE_PATH = '/pages/composition-api/reactivity/watch-effect/watch-effect' + +describe('watchEffect', () => { + const isSafari = process.env.uniTestPlatformInfo.indexOf('safari') > -1 + let page = null + beforeAll(async () => { + page = await program.reLaunch(PAGE_PATH) + await page.waitFor('view') + }) + it('count', async () => { + const count = await page.$('#count') + expect(await count.text()).toBe('count: 0') + + // watch + const watchCountRes = await page.$('#watch-count-res') + expect(await watchCountRes.text()).toBe( + 'watch count result: count: 0, count ref text (flush sync): count: 0') + // track + const watchCountTrackNum = await page.$('#watch-count-track-num') + expect(await watchCountTrackNum.text()).toBe('watch count track number: 3') + + // trigger + const watchCountTriggerNum = await page.$('#watch-count-trigger-num') + expect(await watchCountTriggerNum.text()).toBe('watch count trigger number: 1') + const watchCountCleanupRes = await page.$('#watch-count-cleanup-res') + expect(await watchCountCleanupRes.text()).toBe('watch count cleanup result: watch count cleanup: 0') + + // watch count and obj.num + const watchCountAndObjNumRes = await page.$('#watch-count-obj-num-res') + expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: count: 0, obj.num: 0') + + const incrementBtn = await page.$('.increment-btn') + await incrementBtn.tap() + + expect(await count.text()).toBe('count: 1') + expect(await watchCountRes.text()).toBe( + 'watch count result: count: 1, count ref text (flush sync): count: 0') + expect(await watchCountTrackNum.text()).toBe('watch count track number: 3') + expect(await watchCountTriggerNum.text()).toBe('watch count trigger number: 2') + expect(await watchCountCleanupRes.text()).toBe('watch count cleanup result: watch count cleanup: 1') + + expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: count: 1, obj.num: 0') + + await incrementBtn.tap() + + expect(await count.text()).toBe('count: 2') + expect(await watchCountRes.text()).toBe( + 'watch count result: count: 2, count ref text (flush sync): count: 1') + + expect(await watchCountTrackNum.text()).toBe('watch count track number: 3') + expect(await watchCountTriggerNum.text()).toBe('watch count trigger number: 3') + expect(await watchCountCleanupRes.text()).toBe('watch count cleanup result: watch count cleanup: 2') + + expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: count: 2, obj.num: 0') + + // stop watch + const stopWatchCountBtn = await page.$('.stop-watch-count-btn') + await stopWatchCountBtn.tap() + + await incrementBtn.tap() + + expect(await count.text()).toBe('count: 3') + expect(await watchCountRes.text()).toBe( + 'watch count result: count: 2, count ref text (flush sync): count: 1') + + expect(await watchCountTrackNum.text()).toBe('watch count track number: 3') + expect(await watchCountTriggerNum.text()).toBe('watch count trigger number: 3') + expect(await watchCountCleanupRes.text()).toBe('watch count cleanup result: watch count cleanup: 2') + + expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: count: 3, obj.num: 0') + }) + it('obj', async () => { + const objStr = await page.$('#obj-str') + expect(await objStr.text()).toBe('obj.str: num: 0') + const objNum = await page.$('#obj-num') + expect(await objNum.text()).toBe('obj.num: 0') + const objBool = await page.$('#obj-bool') + expect(await objBool.text()).toBe('obj.bool: false') + const objArr = await page.$('#obj-arr') + expect(await objArr.text()).toBe(isSafari ? 'obj.arr: [ 0]' : 'obj.arr: [0]') + + const watchObjRes = await page.$('#watch-obj-res') + if (process.env.uniTestPlatformInfo.startsWith('android')) { + expect(await watchObjRes.text()).toBe( + 'watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}') + } + if (process.env.uniTestPlatformInfo.startsWith('web')) { + expect(await watchObjRes.text()).toBe( + 'watch obj result: obj: {"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 (flush pre): obj.str: num: 0') + + const watchObjBoolRes = await page.$('#watch-obj-bool-res') + expect(await watchObjBoolRes.text()).toBe( + 'watch obj.bool result: bool: false, obj.bool ref text (flush post): obj.bool: false') + + const watchObjArrRes = await page.$('#watch-obj-arr-res') + expect(await watchObjArrRes.text()).toBe('watch obj.arr result: arr: [0]') + + const updateObjBtn = await page.$('.update-obj-btn') + await updateObjBtn.tap() + + expect(await objStr.text()).toBe('obj.str: num: 1') + expect(await objNum.text()).toBe('obj.num: 1') + expect(await objBool.text()).toBe('obj.bool: true') + expect(await objArr.text()).toBe(isSafari ? 'obj.arr: [ 0, 1]' : 'obj.arr: [0,1]') + + if (process.env.uniTestPlatformInfo.startsWith('android')) { + expect(await watchObjRes.text()).toBe( + 'watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}') + } + if (process.env.uniTestPlatformInfo.startsWith('web')) { + expect(await watchObjRes.text()).toBe( + 'watch obj result: obj: {"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 (flush pre): obj.str: num: 0') + expect(await watchObjBoolRes.text()).toBe( + 'watch obj.bool result: bool: true, obj.bool ref text (flush post): obj.bool: true') + + expect(await watchObjArrRes.text()).toBe('watch obj.arr result: arr: [0,1]') + + const watchCountAndObjNumRes = await page.$('#watch-count-obj-num-res') + expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: count: 3, obj.num: 1') + }) }) \ No newline at end of file -- GitLab