Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
871f8d66
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
374
Star
3
Fork
8
代码
文件
提交
分支
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看板
提交
871f8d66
编写于
1月 25, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test: 测试例优化
上级
2c6afff2
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
224 addition
and
136 deletion
+224
-136
components/CompositionAPILifecycle.uvue
components/CompositionAPILifecycle.uvue
+46
-2
pages.json
pages.json
+39
-38
pages/built-in-component/teleport/sub-container.uvue
pages/built-in-component/teleport/sub-container.uvue
+0
-31
pages/built-in-component/teleport/teleport.test.js
pages/built-in-component/teleport/teleport.test.js
+1
-3
pages/built-in-component/teleport/teleport.uvue
pages/built-in-component/teleport/teleport.uvue
+0
-4
pages/composition-api/basic/define-props/define-props.test.js
...s/composition-api/basic/define-props/define-props.test.js
+2
-1
pages/composition-api/lifecycle/component-lifecycle/component-lifecycle.test.js
...lifecycle/component-lifecycle/component-lifecycle.test.js
+66
-33
pages/composition-api/lifecycle/component-lifecycle/component-lifecycle.uvue
...pi/lifecycle/component-lifecycle/component-lifecycle.uvue
+58
-8
pages/composition-api/lifecycle/page-lifecycle/page-lifecycle.test.js
...ition-api/lifecycle/page-lifecycle/page-lifecycle.test.js
+3
-10
pages/composition-api/lifecycle/page-lifecycle/page-lifecycle.uvue
...position-api/lifecycle/page-lifecycle/page-lifecycle.uvue
+2
-2
pages/composition-api/reactivity/custom-ref/custom-ref.uvue
pages/composition-api/reactivity/custom-ref/custom-ref.uvue
+7
-4
未找到文件。
components/CompositionAPILifecycle.uvue
浏览文件 @
871f8d66
...
...
@@ -9,6 +9,50 @@
import { state, setLifeCycleNum } from '../store/index.uts'
const title = ref('component for composition API lifecycle test')
const emit = defineEmits<{
(e : 'updateIsScroll', val : boolean) : void
}>()
onLoad((_ : OnLoadOptions) => {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 100)
})
onPageShow(() => {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 10)
})
onReady(() => {
// 自动化测试
// TODO: onReady 未触发
setLifeCycleNum(state.lifeCycleNum + 10)
})
onPullDownRefresh(() => {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 10)
})
onPageScroll((_) => {
// 自动化测试
emit('updateIsScroll', true)
})
onReachBottom(() => {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 10)
})
onBackPress((_ : OnBackPressOptions) : boolean | null => {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 10)
return null
})
onPageHide(() => {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 10)
})
onUnload(() => {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 100)
})
onBeforeMount(() => {
// 自动化测试
...
...
@@ -46,9 +90,9 @@
console.log('component for lifecycle test unmounted')
})
//
测试无法
触发
//
TODO: app-android 不
触发
onActivated(() => { })
//
测试无法
触发
//
TODO: app-android 不
触发
onDeactivated(() => { })
const updateTitle = () => {
...
...
pages.json
浏览文件 @
871f8d66
...
...
@@ -335,7 +335,7 @@
"navigationBarTitleText"
:
"render function"
}
},
//
#ifdef
APP
//
#ifdef
APP
{
"path"
:
"pages/composition/mixins/mixins"
,
"style"
:
{
...
...
@@ -348,14 +348,14 @@
"navigationBarTitleText"
:
"mixins-page-2"
}
},
//
#endif
//
#endif
//
#ifdef
WEB
{
"path"
:
"pages/composition/mixins/mixins-web"
,
"style"
:
{
"navigationBarTitleText"
:
"mixins"
}
},
{
"path"
:
"pages/composition/mixins/mixins-web"
,
"style"
:
{
"navigationBarTitleText"
:
"mixins"
}
},
//
#endif
{
"path"
:
"pages/composition/provide/provide"
,
...
...
@@ -600,36 +600,37 @@
"style"
:
{
"navigationBarTitleText"
:
"onScopeDispose"
}
},
{
"path"
:
"pages/composition-api/lifecycle/page-lifecycle/page-lifecycle"
,
"style"
:
{
"navigationBarTitleText"
:
"页面生命周期"
,
"enablePullDownRefresh"
:
true
}
},
{
"path"
:
"pages/composition-api/lifecycle/component-lifecycle/component-lifecycle"
,
"style"
:
{
"navigationBarTitleText"
:
"组件生命周期"
}
},
{
"path"
:
"pages/composition-api/dependency-injection/provide/provide"
,
"style"
:
{
"navigationBarTitleText"
:
"依赖注入"
}
},
{
"path"
:
"pages/built-in-component/teleport/teleport"
,
"style"
:
{
"navigationBarTitleText"
:
"teleport"
,
"enablePullDownRefresh"
:
false
}
},
{
"path"
:
"pages/composition-api/lifecycle/page-lifecycle/page-lifecycle"
,
"style"
:
{
"navigationBarTitleText"
:
"页面生命周期"
,
"enablePullDownRefresh"
:
true
}
},
{
"path"
:
"pages/composition-api/lifecycle/component-lifecycle/component-lifecycle"
,
"style"
:
{
"navigationBarTitleText"
:
"组件生命周期"
,
"enablePullDownRefresh"
:
true
}
},
{
"path"
:
"pages/composition-api/dependency-injection/provide/provide"
,
"style"
:
{
"navigationBarTitleText"
:
"依赖注入"
}
},
{
"path"
:
"pages/built-in-component/teleport/teleport"
,
"style"
:
{
"navigationBarTitleText"
:
"teleport"
,
"enablePullDownRefresh"
:
false
}
}
],
"tabBar"
:
{
...
...
pages/built-in-component/teleport/sub-container.uvue
已删除
100644 → 0
浏览文件 @
2c6afff2
<template>
<view id="teleport" class="sub-container">
<view>
<text class="text">红色区域为子组件</text>
</view>
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
}
}
</script>
<style>
.sub-container {
background-color:red;
height:200px;
padding:10px;
}
.text {
color:#fff;
}
</style>
\ No newline at end of file
pages/built-in-component/teleport/teleport.test.js
浏览文件 @
871f8d66
...
...
@@ -9,9 +9,7 @@ describe('teleport', () => {
it
(
'
teleport
'
,
async
()
=>
{
await
page
.
waitFor
(
500
)
const
image
=
await
program
.
screenshot
({
fullPage
:
true
});
const
image
=
await
program
.
screenshot
();
expect
(
image
).
toMatchImageSnapshot
();
})
})
pages/built-in-component/teleport/teleport.uvue
浏览文件 @
871f8d66
...
...
@@ -4,14 +4,12 @@
<!-- #endif -->
<view id="container" class="container">
<text class="text">.container 区域</text>
<!-- <subContainer></subContainer> -->
<view id="content1" class="content content-1">
<text class="text">content1 区域</text>
</view>
<view id="content2" class="content content-2">
<text class="text">content2 区域</text>
</view>
<!-- <button class="btn" @click="changePosition">点击穿梭</button> -->
<teleport v-if="show" to="#content1" :disabled="disabled">
<view class="send-content">
<text class="send-content-text">内容在.container中,使用teleport在#content1元素中展示</text>
...
...
@@ -24,9 +22,7 @@
</template>
<script>
// import subContainer from './sub-container.uvue'
export default {
// components: { subContainer },
data() {
return {
to: 'content1',
...
...
pages/composition-api/basic/define-props/define-props.test.js
浏览文件 @
871f8d66
const
PAGE_PATH
=
'
/pages/composition-api/basic/define-props/define-props
'
describe
(
'
defineProps
'
,
()
=>
{
describe
(
'
defineProps
'
,
()
=>
{
console
.
log
(
'
process.env.uniTestPlatformInfo---------------
'
,
process
.
env
.
uniTestPlatformInfo
)
const
isSafari
=
process
.
env
.
uniTestPlatformInfo
.
indexOf
(
'
safari
'
)
>
-
1
let
page
=
null
beforeAll
(
async
()
=>
{
...
...
pages/composition-api/lifecycle/component-lifecycle/component-lifecycle.test.js
浏览文件 @
871f8d66
const
PAGE_PATH
=
'
/pages/composition-api/lifecycle/component-lifecycle/component-lifecycle
'
const
INTER_PAGE_PATH
=
'
/pages/app-instance/index/index
'
const
HOME_PATH
=
'
/pages/tab-bar/options-api
'
describe
(
'
component-lifecycle
'
,
()
=>
{
let
page
let
lifeCycleNum
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
HOME_PATH
)
await
page
.
waitFor
(
700
)
const
initLifecycleNum
=
0
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
initLifecycleNum
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
initLifecycleNum
)
let
page
let
lifeCycleNum
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
HOME_PATH
)
await
page
.
waitFor
(
700
)
const
initLifecycleNum
=
0
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
initLifecycleNum
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
initLifecycleNum
)
page
=
await
program
.
navigateTo
(
PAGE_PATH
)
await
page
.
waitFor
(
700
)
})
afterAll
(
async
()
=>
{
const
resetLifecycleNum
=
1100
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
resetLifecycleNum
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
resetLifecycleNum
)
})
page
=
await
program
.
navigateTo
(
PAGE_PATH
)
await
page
.
waitFor
(
700
)
})
//
afterAll(async () => {
//
const resetLifecycleNum = 1100
//
await page.callMethod('setLifeCycleNum', resetLifecycleNum)
//
lifeCycleNum = await page.callMethod('getLifeCycleNum')
//
expect(lifeCycleNum).toBe(resetLifecycleNum)
//
})
it
(
'
onBeforeMount onMounted
'
,
async
()
=>
{
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
2
)
})
it
(
'
onBeforeUpdate onUpdated
'
,
async
()
=>
{
const
updateTitleBtn
=
await
page
.
$
(
'
.component-lifecycle-btn
'
)
await
updateTitleBtn
.
tap
()
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
4
)
})
it
(
'
beforeUnmount unmounted
'
,
async
()
=>
{
page
=
await
program
.
navigateBack
()
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
2
)
})
it
(
'
onLoad onPageShow onReady onBeforeMount onMounted
'
,
async
()
=>
{
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
112
)
await
page
.
callMethod
(
'
pageSetlifeCycleNum
'
,
0
)
})
it
(
'
onBeforeUpdate onUpdated
'
,
async
()
=>
{
const
updateTitleBtn
=
await
page
.
$
(
'
.component-lifecycle-btn
'
)
await
updateTitleBtn
.
tap
()
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
2
)
await
page
.
callMethod
(
'
pageSetlifeCycleNum
'
,
0
)
})
it
(
'
onPullDownRefresh
'
,
async
()
=>
{
await
page
.
callMethod
(
'
pullDownRefresh
'
)
await
page
.
waitFor
(
1500
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
10
)
await
page
.
callMethod
(
'
pageSetlifeCycleNum
'
,
0
)
})
it
(
'
onPageScroll onReachBottom
'
,
async
()
=>
{
await
program
.
pageScrollTo
(
2000
)
// 测试 web 端组件内监听 onPageScroll 不触发
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
const
isScrolled
=
await
page
.
callMethod
(
'
getIsScrolled
'
)
expect
(
isScrolled
).
toBe
(
true
)
}
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
10
)
await
page
.
callMethod
(
'
pageSetlifeCycleNum
'
,
0
)
})
it
(
'
onHide
'
,
async
()
=>
{
page
=
await
program
.
navigateTo
(
INTER_PAGE_PATH
)
await
page
.
waitFor
(
'
view
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
-
10
)
page
=
await
program
.
navigateBack
()
await
page
.
waitFor
(
'
view
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
0
)
await
page
.
callMethod
(
'
pageSetlifeCycleNum
'
,
0
)
})
it
(
'
beforeUnmount unmounted onUnload onBackPress
'
,
async
()
=>
{
page
=
await
program
.
navigateBack
()
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
-
112
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
})
\ No newline at end of file
pages/composition-api/lifecycle/component-lifecycle/component-lifecycle.uvue
浏览文件 @
871f8d66
<template>
<view class="page">
<text class="uni-common-mb">component lifecycle</text>
<component-lifecycle class="component-lifecycle" />
</view>
<!-- #ifdef APP -->
<scroll-view style="flex:1">
<!-- #endif -->
<view class="pag container">
<text class="uni-common-mb">component lifecycle</text>
<component-lifecycle class="component-lifecycle" @updateIsScroll="updateIsScroll" />
<button class="uni-common-mt" @click="scrollToBottom">scrollToBottom</button>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script setup>
import ComponentLifecycle from '@/components/CompositionAPILifecycle.uvue'
import { state } from '@/store/index.uts'
import { state, setLifeCycleNum } from '@/store/index.uts'
const isScrolled = ref(false)
// 自动化测试
const getLifeCycleNum = () : number => {
return state.lifeCycleNum
}
// 自动化测试
const pageSetlifeCycleNum = (num : number) => {
setLifeCycleNum(num)
}
// 自动化测试
const pullDownRefresh = () => {
uni.startPullDownRefresh({
success() {
setTimeout(() => {
uni.stopPullDownRefresh()
}, 1000)
},
})
}
const scrollToBottom = () => {
uni.pageScrollTo({
scrollTop: 3000,
})
}
const updateIsScroll = (val : boolean) => {
isScrolled.value = val
}
// 自动化测试
const getIsScrolled = () : boolean => {
return isScrolled.value
}
defineExpose({
getLifeCycleNum
getLifeCycleNum,
pageSetlifeCycleNum,
pullDownRefresh,
scrollToBottom,
getIsScrolled
})
</script>
\ No newline at end of file
</script>
<style>
.container {
height: 1200px;
}
</style>
\ No newline at end of file
pages/composition-api/lifecycle/page-lifecycle/page-lifecycle.test.js
浏览文件 @
871f8d66
...
...
@@ -5,13 +5,6 @@ let page
let
lifeCycleNum
describe
(
'
page-lifecycle
'
,
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
// TODO: onPageShow onPageHide 别名暂不支持
it
(
'
web
'
,
async
()
=>
{
expect
(
1
).
toBe
(
1
)
})
return
}
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
HOME_PATH
)
await
page
.
waitFor
(
700
)
...
...
@@ -29,14 +22,14 @@ describe('page-lifecycle', () => {
await
page
.
waitFor
(
700
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
120
)
await
page
.
callMethod
(
'
pageSet
l
ifeCycleNum
'
,
0
)
await
page
.
callMethod
(
'
pageSet
L
ifeCycleNum
'
,
0
)
})
it
(
'
onPullDownRefresh
'
,
async
()
=>
{
await
page
.
callMethod
(
'
pullDownRefresh
'
)
await
page
.
waitFor
(
1500
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
10
)
await
page
.
callMethod
(
'
pageSet
l
ifeCycleNum
'
,
0
)
await
page
.
callMethod
(
'
pageSet
L
ifeCycleNum
'
,
0
)
})
it
(
'
onPageScroll onReachBottom
'
,
async
()
=>
{
await
program
.
pageScrollTo
(
2000
)
...
...
@@ -44,7 +37,7 @@ describe('page-lifecycle', () => {
expect
(
isScrolled
).
toBe
(
true
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
10
)
await
page
.
callMethod
(
'
pageSet
l
ifeCycleNum
'
,
0
)
await
page
.
callMethod
(
'
pageSet
L
ifeCycleNum
'
,
0
)
})
it
(
'
onHide
'
,
async
()
=>
{
page
=
await
program
.
navigateTo
(
INTER_PAGE_PATH
)
...
...
pages/composition-api/lifecycle/page-lifecycle/page-lifecycle.uvue
浏览文件 @
871f8d66
...
...
@@ -63,7 +63,7 @@
return state.lifeCycleNum
}
// 自动化测试
const pageSet
l
ifeCycleNum = (num: number) => {
const pageSet
L
ifeCycleNum = (num: number) => {
setLifeCycleNum(num)
}
...
...
@@ -91,7 +91,7 @@
defineExpose({
getLifeCycleNum,
pageSet
l
ifeCycleNum,
pageSet
L
ifeCycleNum,
pullDownRefresh,
scrollToBottom,
getIsScrolled
...
...
pages/composition-api/reactivity/custom-ref/custom-ref.uvue
浏览文件 @
871f8d66
...
...
@@ -7,8 +7,11 @@
</template>
<script setup>
const useCustomRef = (value : UTSJSONObject) : Ref<UTSJSONObject> => {
return customRef((track, trigger) : UTSJSONObject => {
import type { Ref } from 'vue'
const useCustomRef = (value : UTSJSONObject) : Ref<UTSJSONObject> => {
// @ts-ignore
return customRef<UTSJSONObject>((track, trigger) : UTSJSONObject => {
return {
get() : UTSJSONObject {
track()
...
...
@@ -18,11 +21,11 @@
value = newValue
trigger()
}
}
}
as UTSJSONObject
})
}
const state = useCustomRef({ count: 0 })
const state = useCustomRef({ count: 0 }
as UTSJSONObject
)
const increment = () => {
(state.value as UTSJSONObject)['count'] = ((state.value as UTSJSONObject)['count'] as number) + 1
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录