From fa0f47af59ad64ef6784126751448ec6376344b8 Mon Sep 17 00:00:00 2001
From: zhenyuWang <13641039885@163.com>
Date: Tue, 16 Jan 2024 22:10:43 +0800
Subject: [PATCH] feat(composition api): effectScope
---
.../effect-scope/effect-scope.test.js | 42 +++++++++++++++++++
.../reactivity/effect-scope/effect-scope.uvue | 33 ++++++++++++++-
pages/tab-bar/composition-api.uvue | 2 +-
3 files changed, 75 insertions(+), 2 deletions(-)
create mode 100644 pages/composition-api/reactivity/effect-scope/effect-scope.test.js
diff --git a/pages/composition-api/reactivity/effect-scope/effect-scope.test.js b/pages/composition-api/reactivity/effect-scope/effect-scope.test.js
new file mode 100644
index 0000000..ec421d9
--- /dev/null
+++ b/pages/composition-api/reactivity/effect-scope/effect-scope.test.js
@@ -0,0 +1,42 @@
+const PAGE_PATH = '/pages/composition-api/reactivity/effect-scope/effect-scope'
+
+describe('effectScope', () => {
+ if (process.env.uniTestPlatformInfo.startsWith('android')) {
+ let page = null
+ beforeAll(async () => {
+ page = await program.reLaunch(PAGE_PATH)
+ await page.waitFor('view')
+ })
+ it('basic', async () => {
+ const counter = await page.$('#counter')
+ expect(await counter.text()).toBe('counter: 0')
+
+ const watchCounterRes = await page.$('#watch-counter-res')
+ expect(await watchCounterRes.text()).toBe('watch counter result: ')
+
+ const watchEffectCounterRes = await page.$('#watch-effect-counter-res')
+ expect(await watchEffectCounterRes.text()).toBe('watchEffect counter result: counter: 0')
+
+ const incrementCounterBtn = await page.$('#increment-counter-btn')
+ await incrementCounterBtn.tap()
+
+ expect(await counter.text()).toBe('counter: 1')
+ expect(await watchCounterRes.text()).toBe('watch counter result: newVal: 1, oldVal: 0')
+ expect(await watchEffectCounterRes.text()).toBe('watchEffect counter result: counter: 1')
+
+ const stopEffectScopeBtn = await page.$('#stop-effect-scope-btn')
+ await stopEffectScopeBtn.tap()
+
+ await incrementCounterBtn.tap()
+
+ expect(await counter.text()).toBe('counter: 2')
+ expect(await watchCounterRes.text()).toBe('watch counter result: newVal: 1, oldVal: 0')
+ expect(await watchEffectCounterRes.text()).toBe('watchEffect counter result: counter: 1')
+
+ })
+ } else {
+ it('other platform', () => {
+ expect(1).toBe(1)
+ })
+ }
+})
\ No newline at end of file
diff --git a/pages/composition-api/reactivity/effect-scope/effect-scope.uvue b/pages/composition-api/reactivity/effect-scope/effect-scope.uvue
index b3c77f9..524abff 100644
--- a/pages/composition-api/reactivity/effect-scope/effect-scope.uvue
+++ b/pages/composition-api/reactivity/effect-scope/effect-scope.uvue
@@ -1 +1,32 @@
- getCurrentScope
\ No newline at end of file
+
+
+ counter: {{ counter }}
+ watch counter result: {{ watchCounterRes }}
+ watchEffect counter result:
+ {{ watchEffectCounterRes }}
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pages/tab-bar/composition-api.uvue b/pages/tab-bar/composition-api.uvue
index 06954a2..2a88a10 100644
--- a/pages/tab-bar/composition-api.uvue
+++ b/pages/tab-bar/composition-api.uvue
@@ -201,7 +201,7 @@
{
name: 'effectScope',
url: 'effect-scope',
- enable: false,
+ enable: true,
},
{
name: 'getCurrentScope',
--
GitLab