Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
4d404eb0
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
349
Star
2
Fork
7
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello-uvue
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
4d404eb0
编写于
1月 18, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(composition api): 调整示例及测试兼容 web
上级
672d9b42
变更
24
显示空白变更内容
内联
并排
Showing
24 changed file
with
851 addition
and
684 deletion
+851
-684
pages/composition-api/basic/define-emits/array-literal.uvue
pages/composition-api/basic/define-emits/array-literal.uvue
+1
-1
pages/composition-api/basic/define-emits/define-emits.test.js
...s/composition-api/basic/define-emits/define-emits.test.js
+33
-36
pages/composition-api/basic/define-emits/type-emits-1.uvue
pages/composition-api/basic/define-emits/type-emits-1.uvue
+1
-1
pages/composition-api/basic/define-emits/type-emits-2.uvue
pages/composition-api/basic/define-emits/type-emits-2.uvue
+1
-1
pages/composition-api/basic/define-options/define-options.test.js
...mposition-api/basic/define-options/define-options.test.js
+21
-27
pages/composition-api/basic/define-options/define-options.uvue
.../composition-api/basic/define-options/define-options.uvue
+1
-1
pages/composition-api/basic/define-props/define-props.test.js
...s/composition-api/basic/define-props/define-props.test.js
+62
-46
pages/composition-api/basic/define-slots/define-slots.test.js
...s/composition-api/basic/define-slots/define-slots.test.js
+15
-21
pages/composition-api/basic/use-attrs/use-attrs.test.js
pages/composition-api/basic/use-attrs/use-attrs.test.js
+12
-17
pages/composition-api/reactivity/computed/computed.test.js
pages/composition-api/reactivity/computed/computed.test.js
+22
-27
pages/composition-api/reactivity/computed/computed.uvue
pages/composition-api/reactivity/computed/computed.uvue
+1
-1
pages/composition-api/reactivity/is-ref/is-ref.test.js
pages/composition-api/reactivity/is-ref/is-ref.test.js
+16
-22
pages/composition-api/reactivity/ref/ref.test.js
pages/composition-api/reactivity/ref/ref.test.js
+19
-24
pages/composition-api/reactivity/ref/ref.uvue
pages/composition-api/reactivity/ref/ref.uvue
+1
-1
pages/composition-api/reactivity/shallow-reactive/shallow-reactive.test.js
...-api/reactivity/shallow-reactive/shallow-reactive.test.js
+18
-24
pages/composition-api/reactivity/shallow-reactive/shallow-reactive.uvue
...ion-api/reactivity/shallow-reactive/shallow-reactive.uvue
+3
-3
pages/composition-api/reactivity/shallow-ref/shallow-ref.test.js
...omposition-api/reactivity/shallow-ref/shallow-ref.test.js
+19
-25
pages/composition-api/reactivity/shallow-ref/shallow-ref.uvue
...s/composition-api/reactivity/shallow-ref/shallow-ref.uvue
+2
-2
pages/composition-api/reactivity/un-ref/un-ref.test.js
pages/composition-api/reactivity/un-ref/un-ref.test.js
+15
-21
pages/composition-api/reactivity/watch-effect/watch-effect.test.js
...position-api/reactivity/watch-effect/watch-effect.test.js
+136
-83
pages/composition-api/reactivity/watch-effect/watch-effect.uvue
...composition-api/reactivity/watch-effect/watch-effect.uvue
+3
-3
pages/composition-api/reactivity/watch/watch.test.js
pages/composition-api/reactivity/watch/watch.test.js
+161
-105
pages/composition-api/reactivity/watch/watch.uvue
pages/composition-api/reactivity/watch/watch.uvue
+3
-3
pages/tab-bar/composition-api.uvue
pages/tab-bar/composition-api.uvue
+285
-189
未找到文件。
pages/composition-api/basic/define-emits/array-literal.uvue
浏览文件 @
4d404eb0
<template>
<view>
<text class="bold">array literal</text>
<button
id="array-literal-emit-btn" class="
uni-common-mt" @click="emitChange">emit change</button>
<button
class="array-literal-emit-btn
uni-common-mt" @click="emitChange">emit change</button>
</view>
</template>
...
...
pages/composition-api/basic/define-emits/define-emits.test.js
浏览文件 @
4d404eb0
const
PAGE_PATH
=
'
/pages/composition-api/basic/define-emits/define-emits
'
describe
(
'
defineEmits
'
,
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
let
page
=
null
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
...
...
@@ -9,32 +8,30 @@ describe('defineEmits', () => {
})
it
(
'
basic
'
,
async
()
=>
{
const
handleArrayLiteralChangeRes
=
await
page
.
$
(
'
#handle-array-literal-change-res
'
)
expect
(
await
handleArrayLiteralChangeRes
.
text
()).
toBe
(
'
handle array literal comp change result:
'
)
expect
((
await
handleArrayLiteralChangeRes
.
text
()).
trim
()).
toBe
(
'
handle array literal comp change result:
'
)
const
arrayLiteralEmitBtn
=
await
page
.
$
(
'
#array-literal-emit-btn
'
)
const
arrayLiteralEmitBtn
=
await
page
.
$
(
'
.array-literal-emit-btn
'
)
await
arrayLiteralEmitBtn
.
tap
()
expect
(
await
handleArrayLiteralChangeRes
.
text
()).
toBe
(
'
handle array literal comp change result: options is 1
'
)
expect
(
await
handleArrayLiteralChangeRes
.
text
()).
toBe
(
'
handle array literal comp change result: options is 1
'
)
const
handleTypeEmits1ChangeRes
=
await
page
.
$
(
'
#handle-type-emits1-change-res
'
)
expect
(
await
handleTypeEmits1ChangeRes
.
text
()).
toBe
(
'
handle type emits comp change result:
'
)
expect
((
await
handleTypeEmits1ChangeRes
.
text
()).
trim
()).
toBe
(
'
handle type emits comp change result:
'
)
const
typeEmits1EmitBtn
=
await
page
.
$
(
'
#
type-emits1-emit-btn
'
)
const
typeEmits1EmitBtn
=
await
page
.
$
(
'
.
type-emits1-emit-btn
'
)
await
typeEmits1EmitBtn
.
tap
()
expect
(
await
handleTypeEmits1ChangeRes
.
text
()).
toBe
(
'
handle type emits comp change result: options is 2
'
)
const
handleTypeEmits2ChangeRes
=
await
page
.
$
(
'
#handle-type-emits2-change-res
'
)
expect
(
await
handleTypeEmits2ChangeRes
.
text
()).
toBe
(
'
handle type emits named tuple syntax comp change result:
'
)
expect
((
await
handleTypeEmits2ChangeRes
.
text
()).
trim
()).
toBe
(
'
handle type emits named tuple syntax comp change result:
'
)
const
typeEmits2EmitBtn
=
await
page
.
$
(
'
#
type-emits2-emit-btn
'
)
const
typeEmits2EmitBtn
=
await
page
.
$
(
'
.
type-emits2-emit-btn
'
)
await
typeEmits2EmitBtn
.
tap
()
expect
(
await
handleTypeEmits2ChangeRes
.
text
()).
toBe
(
'
handle type emits named tuple syntax comp change result: options is 3
'
)
expect
(
await
handleTypeEmits2ChangeRes
.
text
()).
toBe
(
'
handle type emits named tuple syntax comp change result: options is 3
'
)
})
}
else
{
it
(
'
other platform
'
,
()
=>
{
expect
(
1
).
toBe
(
1
)
})
}
})
\ No newline at end of file
pages/composition-api/basic/define-emits/type-emits-1.uvue
浏览文件 @
4d404eb0
<template>
<view>
<text class="uni-common-mt bold">type emits</text>
<button
id="type-emits1-emit-btn" class="
uni-common-mt" @click="emitChange">emit change</button>
<button
class="type-emits1-emit-btn
uni-common-mt" @click="emitChange">emit change</button>
</view>
</template>
...
...
pages/composition-api/basic/define-emits/type-emits-2.uvue
浏览文件 @
4d404eb0
<template>
<view>
<text class="uni-common-mt bold">type emits named tuple syntax</text>
<button
id="type-emits2-emit-btn" class="
uni-common-mt" @click="emitChange">emit change</button>
<button
class="type-emits2-emit-btn
uni-common-mt" @click="emitChange">emit change</button>
</view>
</template>
...
...
pages/composition-api/basic/define-options/define-options.test.js
浏览文件 @
4d404eb0
const
PAGE_PATH
=
'
/pages/composition-api/basic/define-options/define-options
'
describe
(
'
defineOptions
'
,
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
let
page
=
null
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
...
...
@@ -15,7 +14,7 @@ describe('defineOptions', () => {
const
total
=
await
page
.
$
(
'
#total
'
)
expect
(
await
total
.
text
()).
toBe
(
'
total: 0
'
)
const
incrementBtn
=
await
page
.
$
(
'
#
increment-btn
'
)
const
incrementBtn
=
await
page
.
$
(
'
.
increment-btn
'
)
await
incrementBtn
.
tap
()
expect
(
await
count
.
text
()).
toBe
(
'
count: 1
'
)
...
...
@@ -23,9 +22,4 @@ describe('defineOptions', () => {
const
price
=
await
page
.
data
(
'
price
'
)
expect
(
await
total
.
text
()).
toBe
(
`total:
${
1
*
price
}
`
)
})
}
else
{
it
(
'
other platform
'
,
()
=>
{
expect
(
1
).
toBe
(
1
)
})
}
})
\ No newline at end of file
pages/composition-api/basic/define-options/define-options.uvue
浏览文件 @
4d404eb0
...
...
@@ -3,7 +3,7 @@
<text id="count" class='uni-common-mb'>count: {{ count }}</text>
<text id='double-count' class='uni-common-mb'>double count: {{ doubleCount}}</text>
<text id="total" class='uni-common-mb'>total: {{ total}}</text>
<button
id
="increment-btn" @click="increment">increment</button>
<button
class
="increment-btn" @click="increment">increment</button>
</view>
</template>
...
...
pages/composition-api/basic/define-props/define-props.test.js
浏览文件 @
4d404eb0
const
PAGE_PATH
=
'
/pages/composition-api/basic/define-props/define-props
'
describe
(
'
defineProps
'
,
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
let
page
=
null
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
...
...
@@ -15,9 +14,17 @@ describe('defineProps', () => {
const
arrayLiteralBool
=
await
page
.
$
(
'
#array-literal-bool
'
)
expect
(
await
arrayLiteralBool
.
text
()).
toBe
(
'
bool: false
'
)
const
arrayLiteralArr
=
await
page
.
$
(
'
#array-literal-arr
'
)
expect
(
await
arrayLiteralArr
.
text
()).
toBe
(
'
arr: ["a","b","c"]
'
)
expect
((
await
arrayLiteralArr
.
text
()).
replaceAll
(
'
\n
'
,
''
)).
toBe
(
'
arr: ["a","b","c"]
'
)
const
arrayLiteralObj
=
await
page
.
$
(
'
#array-literal-obj
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
arrayLiteralObj
.
text
()).
toBe
(
'
obj: {"arr":[1,2,3],"num":0,"str":"obj str"}
'
)
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
expect
((
await
arrayLiteralObj
.
text
()).
replaceAll
(
'
\n
'
,
''
)).
toBe
(
'
obj: {"str": "obj str","num": 0,"arr": [1,2,3]}
'
)
}
const
arrayLiteralFn
=
await
page
.
$
(
'
#array-literal-fn
'
)
expect
(
await
arrayLiteralFn
.
text
()).
toBe
(
'
fn: fn res
'
)
...
...
@@ -28,9 +35,16 @@ describe('defineProps', () => {
const
objectLiteralBool
=
await
page
.
$
(
'
#object-literal-bool
'
)
expect
(
await
objectLiteralBool
.
text
()).
toBe
(
'
bool: false
'
)
const
objectLiteralArr
=
await
page
.
$
(
'
#object-literal-arr
'
)
expect
(
await
objectLiteralArr
.
text
()).
toBe
(
'
arr: ["a","b","c"]
'
)
expect
((
await
objectLiteralArr
.
text
()).
replaceAll
(
'
\n
'
,
''
)).
toBe
(
'
arr: ["a","b","c"]
'
)
const
objectLiteralObj
=
await
page
.
$
(
'
#object-literal-obj
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
objectLiteralObj
.
text
()).
toBe
(
'
obj: {"a":1}
'
)
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
expect
((
await
objectLiteralObj
.
text
()).
replaceAll
(
'
\n
'
,
''
)).
toBe
(
'
obj: {"a": 1}
'
)
}
const
objectLiteralFn
=
await
page
.
$
(
'
#object-literal-fn
'
)
expect
(
await
objectLiteralFn
.
text
()).
toBe
(
'
fn: fn res
'
)
...
...
@@ -41,15 +55,17 @@ describe('defineProps', () => {
const
typeBool
=
await
page
.
$
(
'
#type-bool
'
)
expect
(
await
typeBool
.
text
()).
toBe
(
'
bool: false
'
)
const
typeArr
=
await
page
.
$
(
'
#type-arr
'
)
expect
(
await
typeArr
.
text
()).
toBe
(
'
arr: ["a","b","c"]
'
)
expect
((
await
typeArr
.
text
()).
replaceAll
(
'
\n
'
,
''
)).
toBe
(
'
arr: ["a","b","c"]
'
)
const
typeObj
=
await
page
.
$
(
'
#type-obj
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
typeObj
.
text
()).
toBe
(
'
obj: {"arr":[1,2,3],"num":0,"str":"obj str"}
'
)
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
expect
((
await
typeObj
.
text
()).
replaceAll
(
'
\n
'
,
''
)).
toBe
(
'
obj: {"str": "obj str","num": 0,"arr": [1,2,3]}
'
)
}
const
typeFn
=
await
page
.
$
(
'
#type-fn
'
)
expect
(
await
typeFn
.
text
()).
toBe
(
'
fn: fn res
'
)
})
}
else
{
it
(
'
other platform
'
,
()
=>
{
expect
(
1
).
toBe
(
1
)
})
}
})
\ No newline at end of file
pages/composition-api/basic/define-slots/define-slots.test.js
浏览文件 @
4d404eb0
const
PAGE_PATH
=
'
/pages/composition-api/basic/define-slots/define-slots
'
describe
(
'
defineSlots
'
,
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
let
page
=
null
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
...
...
@@ -15,11 +14,6 @@ describe('defineSlots', () => {
expect
(
await
slotContent
.
text
()).
toBe
(
'
default slot num: 0
'
)
const
slotFooter
=
await
page
.
$
(
'
#slot-footer
'
)
expect
(
await
slotFooter
.
text
()).
toBe
(
'
footer slot arr: ["a","b","c"]
'
)
expect
((
await
slotFooter
.
text
()).
replaceAll
(
'
\n
'
,
''
)).
toBe
(
'
footer slot arr: ["a","b","c"]
'
)
})
}
else
{
it
(
'
other platform
'
,
()
=>
{
expect
(
1
).
toBe
(
1
)
})
}
})
\ No newline at end of file
pages/composition-api/basic/use-attrs/use-attrs.test.js
浏览文件 @
4d404eb0
const
PAGE_PATH
=
'
/pages/composition-api/basic/use-attrs/use-attrs
'
describe
(
'
useAttrs
'
,
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
let
page
=
null
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
...
...
@@ -14,9 +13,5 @@ describe('useAttrs', () => {
const
attrsMsg
=
await
page
.
$
(
'
#attrs-msg
'
)
expect
(
await
attrsMsg
.
text
()).
toBe
(
'
attrs.msg: msg
'
)
})
}
else
{
it
(
'
other platform
'
,
()
=>
{
expect
(
1
).
toBe
(
1
)
})
}
})
\ No newline at end of file
pages/composition-api/reactivity/computed/computed.test.js
浏览文件 @
4d404eb0
const
PAGE_PATH
=
'
/pages/composition-api/reactivity/computed/computed
'
describe
(
'
computed
'
,
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
let
page
=
null
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
...
...
@@ -14,21 +13,17 @@ describe('computed', () => {
expect
(
await
doubleCount
.
text
()).
toBe
(
'
computed double count: 0
'
)
const
objArr
=
await
page
.
$
(
'
#obj-arr
'
)
expect
(
await
objArr
.
text
(
)).
toBe
(
'
obj.arr: [1,2,3]
'
)
expect
((
await
objArr
.
text
()).
replaceAll
(
'
\n
'
,
''
)).
toBe
(
'
obj.arr: [1,2,3]
'
)
const
objArrLen
=
await
page
.
$
(
'
#obj-arr-len
'
)
expect
(
await
objArrLen
.
text
()).
toBe
(
'
computed obj.arr.length: 3
'
)
const
updateBtn
=
await
page
.
$
(
'
#
update-btn
'
)
const
updateBtn
=
await
page
.
$
(
'
.
update-btn
'
)
await
updateBtn
.
tap
()
expect
(
await
count
.
text
()).
toBe
(
'
count: 1
'
)
expect
(
await
doubleCount
.
text
()).
toBe
(
'
computed double count: 2
'
)
expect
(
await
objArr
.
text
(
)).
toBe
(
'
obj.arr: [1,2,3,4]
'
)
expect
((
await
objArr
.
text
()).
replaceAll
(
'
\n
'
,
''
)).
toBe
(
'
obj.arr: [1,2,3,4]
'
)
expect
(
await
objArrLen
.
text
()).
toBe
(
'
computed obj.arr.length: 4
'
)
})
}
else
{
it
(
'
other platform
'
,
()
=>
{
expect
(
1
).
toBe
(
1
)
})
}
})
\ No newline at end of file
pages/composition-api/reactivity/computed/computed.uvue
浏览文件 @
4d404eb0
...
...
@@ -4,7 +4,7 @@
<text id="double-count" class="uni-common-mb">computed double count: {{ doubleCount }}</text>
<text id="obj-arr" class="uni-common-mb">obj.arr: {{ obj.arr }}</text>
<text id="obj-arr-len" class="uni-common-mb">computed obj.arr.length: {{ objArrLen }}</text>
<button
id
="update-btn" @click="update">update</button>
<button
class
="update-btn" @click="update">update</button>
</view>
</template>
...
...
pages/composition-api/reactivity/is-ref/is-ref.test.js
浏览文件 @
4d404eb0
const
PAGE_PATH
=
'
/pages/composition-api/reactivity/is-ref/is-ref
'
describe
(
'
isRef
'
,
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
let
page
=
null
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
...
...
@@ -18,9 +17,4 @@ describe('isRef', () => {
const
isRefCount
=
await
page
.
$
(
'
#is-ref-count
'
)
expect
(
await
isRefCount
.
text
()).
toBe
(
'
isRef count: false
'
)
})
}
else
{
it
(
'
other platform
'
,
()
=>
{
expect
(
1
).
toBe
(
1
)
})
}
})
\ No newline at end of file
pages/composition-api/reactivity/ref/ref.test.js
浏览文件 @
4d404eb0
const
PAGE_PATH
=
'
/pages/composition-api/reactivity/ref/ref
'
describe
(
'
ref
'
,
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
let
page
=
null
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
...
...
@@ -15,16 +14,12 @@ describe('ref', () => {
const
counterCount
=
await
page
.
$
(
'
#counter-count
'
)
expect
(
await
counterCount
.
text
()).
toBe
(
'
counter.count: 0
'
)
const
incrementBtn
=
await
page
.
$
(
'
#
increment-btn
'
)
const
incrementBtn
=
await
page
.
$
(
'
.
increment-btn
'
)
await
incrementBtn
.
tap
()
expect
(
await
count1
.
text
()).
toBe
(
'
count1: 2
'
)
expect
(
await
count2
.
text
()).
toBe
(
'
count2: 2
'
)
expect
(
await
counterCount
.
text
()).
toBe
(
'
counter.count: 1
'
)
})
}
else
{
it
(
'
other platform
'
,
()
=>
{
expect
(
1
).
toBe
(
1
)
})
}
})
\ No newline at end of file
pages/composition-api/reactivity/ref/ref.uvue
浏览文件 @
4d404eb0
...
...
@@ -3,7 +3,7 @@
<text id="count1" class="uni-common-mb">count1: {{ count1 }}</text>
<text id="count2" class="uni-common-mb">count2: {{ count2 }}</text>
<text id="counter-count" class="uni-common-mb">counter.count: {{ counter.count }}</text>
<button
id
="increment-btn" @click="increment">increment</button>
<button
class
="increment-btn" @click="increment">increment</button>
</view>
</template>
...
...
pages/composition-api/reactivity/shallow-reactive/shallow-reactive.test.js
浏览文件 @
4d404eb0
const
PAGE_PATH
=
'
/pages/composition-api/reactivity/shallow-reactive/shallow-reactive
'
describe
(
'
shallowReactive
'
,
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
let
page
=
null
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
...
...
@@ -14,20 +13,15 @@ describe('shallowReactive', () => {
const
stateNestedCount
=
await
page
.
$
(
'
#state-nested-count
'
)
expect
(
await
stateNestedCount
.
text
()).
toBe
(
'
state.nested.count: 0
'
)
const
incrementStateNestedCountBtn
=
await
page
.
$
(
'
#
increment-state-nested-count-btn
'
)
const
incrementStateNestedCountBtn
=
await
page
.
$
(
'
.
increment-state-nested-count-btn
'
)
await
incrementStateNestedCountBtn
.
tap
()
expect
(
await
stateNestedCount
.
text
()).
toBe
(
'
state.nested.count: 0
'
)
const
incrementStateCountBtn
=
await
page
.
$
(
'
#
increment-state-count-btn
'
)
const
incrementStateCountBtn
=
await
page
.
$
(
'
.
increment-state-count-btn
'
)
await
incrementStateCountBtn
.
tap
()
expect
(
await
stateCount
.
text
()).
toBe
(
'
state.count: 1
'
)
expect
(
await
stateNestedCount
.
text
()).
toBe
(
'
state.nested.count: 1
'
)
})
}
else
{
it
(
'
other platform
'
,
()
=>
{
expect
(
1
).
toBe
(
1
)
})
}
})
\ No newline at end of file
pages/composition-api/reactivity/shallow-reactive/shallow-reactive.uvue
浏览文件 @
4d404eb0
<template>
<view class="page">
<text id="state-count" class="uni-common-mb">state.count: {{ state.count }}</text>
<text id="state-count" class="uni-common-mb"
:data-count="state.count"
>state.count: {{ state.count }}</text>
<text id="state-nested-count" class="uni-common-mb">state.nested.count: {{ state.nested.count }}</text>
<button
id="increment-state-count-btn" class="
uni-common-mb" @click="incrementStateCount">
<button
class="increment-state-count-btn
uni-common-mb" @click="incrementStateCount">
increment state.count
</button>
<button
id
="increment-state-nested-count-btn" @click="incrementStateNestedCount">
<button
class
="increment-state-nested-count-btn" @click="incrementStateNestedCount">
increment state.nested.count
</button>
</view>
...
...
pages/composition-api/reactivity/shallow-ref/shallow-ref.test.js
浏览文件 @
4d404eb0
const
PAGE_PATH
=
'
/pages/composition-api/reactivity/shallow-ref/shallow-ref
'
describe
(
'
shallowRef
'
,
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
let
page
=
null
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
...
...
@@ -11,19 +10,14 @@ describe('shallowRef', () => {
const
stateCount
=
await
page
.
$
(
'
#state-count
'
)
expect
(
await
stateCount
.
text
()).
toBe
(
'
state.count: 0
'
)
const
incrementStateCountBtn
=
await
page
.
$
(
'
#increment-state-count-btn
'
)
const
incrementStateCountBtn
=
await
page
.
$
(
'
.increment-state-count-btn
'
)
await
incrementStateCountBtn
.
tap
()
expect
(
await
stateCount
.
text
()).
toBe
(
'
state.count: 0
'
)
const
updateStateBtn
=
await
page
.
$
(
'
#update-state-btn
'
)
const
updateStateBtn
=
await
page
.
$
(
'
.update-state-btn
'
)
await
updateStateBtn
.
tap
()
expect
(
await
stateCount
.
text
()).
toBe
(
'
state.count: 1
'
)
})
}
else
{
it
(
'
other platform
'
,
()
=>
{
expect
(
1
).
toBe
(
1
)
})
}
})
\ No newline at end of file
pages/composition-api/reactivity/shallow-ref/shallow-ref.uvue
浏览文件 @
4d404eb0
<template>
<view class="page">
<text id="state-count" class="uni-common-mb">state.count: {{ state.count }}</text>
<button
id="increment-state-count-btn" class="
uni-common-mb" @click="incrementStateCount">increment
<button
class="increment-state-count-btn
uni-common-mb" @click="incrementStateCount">increment
state.count</button>
<button
id
="update-state-btn" @click="updateState">update state</button>
<button
class
="update-state-btn" @click="updateState">update state</button>
</view>
</template>
...
...
pages/composition-api/reactivity/un-ref/un-ref.test.js
浏览文件 @
4d404eb0
const
PAGE_PATH
=
'
/pages/composition-api/reactivity/un-ref/un-ref
'
describe
(
'
unref
'
,
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
let
page
=
null
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
...
...
@@ -18,9 +17,4 @@ describe('unref', () => {
const
isRefCount
=
await
page
.
$
(
'
#count-type
'
)
expect
(
await
isRefCount
.
text
()).
toBe
(
'
count type: number
'
)
})
}
else
{
it
(
'
other platform
'
,
()
=>
{
expect
(
1
).
toBe
(
1
)
})
}
})
\ No newline at end of file
pages/composition-api/reactivity/watch-effect/watch-effect.test.js
浏览文件 @
4d404eb0
const
PAGE_PATH
=
'
/pages/composition-api/reactivity/watch-effect/watch-effect
'
describe
(
'
watchEffect
'
,
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
let
page
=
null
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
...
...
@@ -13,9 +12,14 @@ describe('watchEffect', () => {
// watch
const
watchCountRes
=
await
page
.
$
(
'
#watch-count-res
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 0, count ref text (flush sync): count: 0
'
)
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 0, count ref text (flush sync): null
'
)
}
// track
const
watchCountTrackNum
=
await
page
.
$
(
'
#watch-count-track-num
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
...
...
@@ -30,12 +34,18 @@ describe('watchEffect', () => {
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
'
)
const
incrementBtn
=
await
page
.
$
(
'
.
increment-btn
'
)
await
incrementBtn
.
tap
()
expect
(
await
count
.
text
()).
toBe
(
'
count: 1
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 1, count ref text (flush sync): count: 0
'
)
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 1, count ref text (flush sync): null
'
)
}
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
'
)
...
...
@@ -45,8 +55,14 @@ describe('watchEffect', () => {
await
incrementBtn
.
tap
()
expect
(
await
count
.
text
()).
toBe
(
'
count: 2
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 2, count ref text (flush sync): count: 1
'
)
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 2, count ref text (flush sync): null
'
)
}
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
'
)
...
...
@@ -54,14 +70,20 @@ describe('watchEffect', () => {
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
'
)
const
stopWatchCountBtn
=
await
page
.
$
(
'
.
stop-watch-count-btn
'
)
await
stopWatchCountBtn
.
tap
()
await
incrementBtn
.
tap
()
expect
(
await
count
.
text
()).
toBe
(
'
count: 3
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 2, count ref text (flush sync): count: 1
'
)
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 2, count ref text (flush sync): null
'
)
}
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
'
)
...
...
@@ -76,42 +98,73 @@ describe('watchEffect', () => {
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]
'
)
expect
((
await
objArr
.
text
()).
replaceAll
(
'
\n
'
,
''
)).
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
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchObjStrRes
.
text
()).
toBe
(
'
watch obj.str result: str: num: 0, obj.str ref text (flush pre): obj.str: num: 0
'
)
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
expect
(
await
watchObjStrRes
.
text
()).
toBe
(
'
watch obj.str result: str: num: 0, obj.str ref text (flush pre): null
'
)
}
const
watchObjBoolRes
=
await
page
.
$
(
'
#watch-obj-bool-res
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchObjBoolRes
.
text
()).
toBe
(
'
watch obj.bool result: bool: false, obj.bool ref text (flush post): obj.bool: false
'
)
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
expect
(
await
watchObjBoolRes
.
text
()).
toBe
(
'
watch obj.bool result: bool: false, obj.bool ref text (flush post): null
'
)
}
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
'
)
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]
'
)
expect
((
await
objArr
.
text
()).
replaceAll
(
'
\n
'
,
''
)).
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]}
'
)
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchObjStrRes
.
text
()).
toBe
(
'
watch obj.str result: str: num: 1, obj.str ref text (flush pre): obj.str: num: 0
'
)
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
expect
(
await
watchObjStrRes
.
text
()).
toBe
(
'
watch obj.str result: str: num: 1, obj.str ref text (flush pre): null
'
)
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchObjBoolRes
.
text
()).
toBe
(
'
watch obj.bool result: bool: true, obj.bool ref text (flush post): obj.bool: true
'
)
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
expect
(
await
watchObjBoolRes
.
text
()).
toBe
(
'
watch obj.bool result: bool: true, obj.bool ref text (flush post): null
'
)
}
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
'
)
})
}
else
{
it
(
'
other platform
'
,
()
=>
{
expect
(
1
).
toBe
(
1
)
})
}
})
\ No newline at end of file
pages/composition-api/reactivity/watch-effect/watch-effect.uvue
浏览文件 @
4d404eb0
...
...
@@ -10,10 +10,10 @@
{{ watchCountTriggerNum }}</text>
<text id="watch-count-cleanup-res" class="uni-common-mb">watch count cleanup result:
{{ watchCountCleanupRes }}</text>
<button
id="increment-btn" class="
uni-common-mb" @click="increment">
<button
class="increment-btn
uni-common-mb" @click="increment">
increment
</button>
<button
id="stop-watch-count-btn" class="
uni-common-mb" @click="triggerStopWatchCount">
<button
class="stop-watch-count-btn
uni-common-mb" @click="triggerStopWatchCount">
stop watch count
</button>
<text id="obj-str" ref="objStrRef" class="uni-common-mb">obj.str: {{ obj.str }}</text>
...
...
@@ -24,7 +24,7 @@
<text id="watch-obj-str-res" class="uni-common-mb">watch obj.str result: {{ watchObjStrRes }}</text>
<text id="watch-obj-bool-res" class="uni-common-mb">watch obj.bool result: {{ watchObjBoolRes }}</text>
<text id="watch-obj-arr-res" class="uni-common-mb">watch obj.arr result: {{ watchObjArrRes }}</text>
<button
id="update-obj-btn" class="
uni-common-mb" @click="updateObj">
<button
class="update-obj-btn
uni-common-mb" @click="updateObj">
update obj
</button>
<text id="watch-count-obj-num-res" class="uni-common-mb">watch count and obj.num result:
...
...
pages/composition-api/reactivity/watch/watch.test.js
浏览文件 @
4d404eb0
const
PAGE_PATH
=
'
/pages/composition-api/reactivity/watch/watch
'
describe
(
'
watch
'
,
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
let
page
=
null
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
...
...
@@ -13,7 +12,7 @@ describe('watch', () => {
// watch
const
watchCountRes
=
await
page
.
$
(
'
#watch-count-res
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result:
'
)
expect
((
await
watchCountRes
.
text
()).
trim
()).
toBe
(
'
watch count result:
'
)
// track
const
watchCountTrackNum
=
await
page
.
$
(
'
#watch-count-track-num
'
)
...
...
@@ -23,35 +22,54 @@ describe('watch', () => {
const
watchCountTriggerNum
=
await
page
.
$
(
'
#watch-count-trigger-num
'
)
expect
(
await
watchCountTriggerNum
.
text
()).
toBe
(
'
watch count trigger number: 0
'
)
const
watchCountCleanupRes
=
await
page
.
$
(
'
#watch-count-cleanup-res
'
)
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result:
'
)
expect
((
await
watchCountCleanupRes
.
text
()).
trim
()).
toBe
(
'
watch count cleanup result:
'
)
// 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:
'
)
expect
((
await
watchCountAndObjNumRes
.
text
()).
trim
()).
toBe
(
'
watch count and obj.num result:
'
)
const
incrementBtn
=
await
page
.
$
(
'
#
increment-btn
'
)
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, prevCount: 0, count ref text (flush sync): count: 0
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 1, prevCount: 0, count ref text (flush sync): count: 0
'
)
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 1, prevCount: 0, count ref text (flush sync): null
'
)
}
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 2
'
)
expect
(
await
watchCountTriggerNum
.
text
()).
toBe
(
'
watch count trigger number: 1
'
)
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result:
'
)
expect
((
await
watchCountCleanupRes
.
text
()).
trim
()).
toBe
(
'
watch count cleanup result:
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: state: [1,0], preState: [0,0]
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: state: [1,0], preState: [0,0]
'
)
await
incrementBtn
.
tap
()
expect
(
await
count
.
text
()).
toBe
(
'
count: 2
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 2, prevCount: 1, count ref text (flush sync): count: 1
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 2, prevCount: 1, count ref text (flush sync): count: 1
'
)
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 2, prevCount: 1, count ref text (flush sync): null
'
)
}
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 2
'
)
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: state: [2,0], preState: [1,0]
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: state: [2,0], preState: [1,0]
'
)
// stop watch
const
stopWatchCountBtn
=
await
page
.
$
(
'
#
stop-watch-count-btn
'
)
const
stopWatchCountBtn
=
await
page
.
$
(
'
.
stop-watch-count-btn
'
)
await
stopWatchCountBtn
.
tap
()
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result: watch count cleanup: 2
'
)
...
...
@@ -59,12 +77,20 @@ describe('watch', () => {
await
incrementBtn
.
tap
()
expect
(
await
count
.
text
()).
toBe
(
'
count: 3
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 2, prevCount: 1, count ref text (flush sync): count: 1
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 2, prevCount: 1, count ref text (flush sync): count: 1
'
)
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 2, prevCount: 1, count ref text (flush sync): null
'
)
}
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 2
'
)
expect
(
await
watchCountTriggerNum
.
text
()).
toBe
(
'
watch count trigger number: 2
'
)
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result: watch count cleanup: 2
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: state: [3,0], preState: [2,0]
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: state: [3,0], preState: [2,0]
'
)
})
it
(
'
obj
'
,
async
()
=>
{
const
objStr
=
await
page
.
$
(
'
#obj-str
'
)
...
...
@@ -74,36 +100,66 @@ describe('watch', () => {
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]
'
)
expect
((
await
objArr
.
text
()).
replaceAll
(
'
\n
'
,
''
)).
toBe
(
'
obj.arr: [0]
'
)
const
watchObjRes
=
await
page
.
$
(
'
#watch-obj-res
'
)
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}, prevObj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}, prevObj: {"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]}, prevObj: null
'
)
}
const
watchObjStrRes
=
await
page
.
$
(
'
#watch-obj-str-res
'
)
expect
(
await
watchObjStrRes
.
text
()).
toBe
(
'
watch obj.str result:
'
)
expect
((
await
watchObjStrRes
.
text
()).
trim
()).
toBe
(
'
watch obj.str result:
'
)
const
watchObjBoolRes
=
await
page
.
$
(
'
#watch-obj-bool-res
'
)
expect
(
await
watchObjBoolRes
.
text
()).
toBe
(
'
watch obj.bool result:
'
)
expect
((
await
watchObjBoolRes
.
text
()).
trim
()).
toBe
(
'
watch obj.bool result:
'
)
const
watchObjArrRes
=
await
page
.
$
(
'
#watch-obj-arr-res
'
)
expect
(
await
watchObjArrRes
.
text
()).
toBe
(
'
watch obj.arr result:
'
)
expect
((
await
watchObjArrRes
.
text
()).
trim
()).
toBe
(
'
watch obj.arr result:
'
)
const
updateObjBtn
=
await
page
.
$
(
'
#
update-obj-btn
'
)
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]
'
)
expect
((
await
objArr
.
text
()).
replaceAll
(
'
\n
'
,
''
)).
toBe
(
'
obj.arr: [0,1]
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
watch obj result: obj: {"arr":[0,1],"bool":true,"num":1,"str":"num: 1"}, prevObj: {"arr":[0,1],"bool":true,"num":1,"str":"num: 1"}
'
)
}
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]}, prevObj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}
'
)
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchObjStrRes
.
text
()).
toBe
(
'
watch obj.str result: str: num: 1, prevStr: num: 0, obj.str ref text (flush pre): obj.str: num: 0
'
)
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
expect
(
await
watchObjStrRes
.
text
()).
toBe
(
'
watch obj.str result: str: num: 1, prevStr: num: 0, obj.str ref text (flush pre): null
'
)
}
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
watch obj result: obj: {"arr":[0,1],"bool":true,"num":1,"str":"num: 1"}, prevObj: {"arr":[0,1],"bool":true,"num":1,"str":"num: 1"}
'
)
expect
(
await
watchObjStrRes
.
text
()).
toBe
(
'
watch obj.str result: str: num: 1, prevStr: num: 0, obj.str ref text (flush pre): obj.str: num: 0
'
)
expect
(
await
watchObjBoolRes
.
text
()).
toBe
(
'
watch obj.bool result: bool: true, prevBool: false, obj.bool ref text (flush post): obj.bool: true
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchObjBoolRes
.
text
()).
toBe
(
'
watch obj.bool result: bool: true, prevBool: false, obj.bool ref text (flush post): obj.bool: true
'
)
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
expect
(
await
watchObjBoolRes
.
text
()).
toBe
(
'
watch obj.bool result: bool: true, prevBool: false, obj.bool ref text (flush post): null
'
)
}
expect
(
await
watchObjArrRes
.
text
()).
toBe
(
'
watch obj.arr result: arr: [0,1], prevArr: [0,1]
'
)
const
watchCountAndObjNumRes
=
await
page
.
$
(
'
#watch-count-obj-num-res
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: state: [3,1], preState: [3,0]
'
)
})
}
else
{
it
(
'
other platform
'
,
()
=>
{
expect
(
1
).
toBe
(
1
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: state: [3,1], preState: [3,0]
'
)
})
}
})
\ No newline at end of file
pages/composition-api/reactivity/watch/watch.uvue
浏览文件 @
4d404eb0
...
...
@@ -10,10 +10,10 @@
{{ watchCountTriggerNum }}</text>
<text id="watch-count-cleanup-res" class="uni-common-mb">watch count cleanup result:
{{ watchCountCleanupRes }}</text>
<button
id="increment-btn" class="
uni-common-mb" @click="increment">
<button
class="increment-btn
uni-common-mb" @click="increment">
increment
</button>
<button
id="stop-watch-count-btn" class="
uni-common-mb" @click="triggerStopWatchCount">
<button
class="stop-watch-count-btn
uni-common-mb" @click="triggerStopWatchCount">
stop watch count
</button>
<text id="obj-str" ref="objStrRef" class="uni-common-mb">obj.str: {{ obj.str }}</text>
...
...
@@ -24,7 +24,7 @@
<text id="watch-obj-str-res" class="uni-common-mb">watch obj.str result: {{ watchObjStrRes }}</text>
<text id="watch-obj-bool-res" class="uni-common-mb">watch obj.bool result: {{ watchObjBoolRes }}</text>
<text id="watch-obj-arr-res" class="uni-common-mb">watch obj.arr result: {{ watchObjArrRes }}</text>
<button
id="update-obj-btn" class="
uni-common-mb" @click="updateObj">
<button
class="update-obj-btn
uni-common-mb" @click="updateObj">
update obj
</button>
<text id="watch-count-obj-num-res" class="uni-common-mb">watch count and obj.num result:
...
...
pages/tab-bar/composition-api.uvue
浏览文件 @
4d404eb0
...
...
@@ -45,7 +45,7 @@
{
name: 'defineProps',
url: 'define-props',
enable: fals
e,
enable: tru
e,
},
{
name: 'defineEmits',
...
...
@@ -55,7 +55,12 @@
{
name: 'defineExpose',
url: 'define-expose',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'defineOptions',
...
...
@@ -67,15 +72,25 @@
url: 'define-slots',
enable: true,
},
{
{
name: 'defineModel',
url: 'define-model',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'useSlots',
url: 'use-slots',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'useAttrs',
...
...
@@ -101,12 +116,22 @@
{
name: 'reactive',
url: 'reactive',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'readonly',
url: 'readonly',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'watch',
...
...
@@ -121,12 +146,22 @@
{
name: 'watchPostEffect',
url: 'watch-post-effect',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'watchSyncEffect',
url: 'watch-sync-effect',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'isRef',
...
...
@@ -141,36 +176,62 @@
{
name: 'toRef',
url: 'to-ref',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'toValue',
url: 'to-value',
// #ifdef APP
enable: true,
// #else
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'toRefs',
url: 'to-refs',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'isProxy',
url: 'is-proxy',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'isReactive',
url: 'is-reactive',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'isReadonly',
url: 'is-readonly',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'shallowRef',
...
...
@@ -180,12 +241,22 @@
{
name: 'triggerRef',
url: 'trigger-ref',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'customRef',
url: 'custom-ref',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'shallowReactive',
...
...
@@ -195,12 +266,22 @@
{
name: 'shallowReadonly',
url: 'shallow-readonly',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'toRaw',
url: 'to-raw',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'markRaw',
...
...
@@ -210,17 +291,32 @@
{
name: 'effectScope',
url: 'effect-scope',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'getCurrentScope',
url: 'get-current-scope',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'onScopeDispose',
url: 'on-scope-dispose',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
] as PageItem[],
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录