Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
c9e2ba46
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
401
Star
3
Fork
10
代码
文件
提交
分支
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看板
提交
c9e2ba46
编写于
11月 25, 2023
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' into dev
上级
9f63eced
1e2ff0c3
变更
27
隐藏空白更改
内联
并排
Showing
27 changed file
with
499 addition
and
246 deletion
+499
-246
App.uvue
App.uvue
+60
-58
components/Bar.uvue
components/Bar.uvue
+3
-0
components/Foo.uvue
components/Foo.uvue
+3
-0
jest-setup.js
jest-setup.js
+3
-0
jest.config.js
jest.config.js
+8
-9
pages.json
pages.json
+43
-10
pages/component-instance/attrs/child.uvue
pages/component-instance/attrs/child.uvue
+18
-2
pages/component-instance/parent/child.uvue
pages/component-instance/parent/child.uvue
+4
-0
pages/component-instance/refs/refs.uvue
pages/component-instance/refs/refs.uvue
+2
-2
pages/component-instance/slots/slot.uvue
pages/component-instance/slots/slot.uvue
+26
-28
pages/directive/v-html/v-html.test.js
pages/directive/v-html/v-html.test.js
+13
-0
pages/directive/v-html/v-html.uvue
pages/directive/v-html/v-html.uvue
+13
-0
pages/examples/set-custom-child-component-root-node-class/child.uvue
...les/set-custom-child-component-root-node-class/child.uvue
+15
-0
pages/examples/set-custom-child-component-root-node-class/set-custom-child-component-root-node-class.test.js
...-class/set-custom-child-component-root-node-class.test.js
+15
-0
pages/examples/set-custom-child-component-root-node-class/set-custom-child-component-root-node-class.uvue
...ode-class/set-custom-child-component-root-node-class.uvue
+25
-0
pages/index.uvue
pages/index.uvue
+33
-14
pages/lifecycle/component/component.test.js
pages/lifecycle/component/component.test.js
+3
-1
pages/lifecycle/page/page.test.js
pages/lifecycle/page/page.test.js
+73
-72
pages/rendering/component/component.test.js
pages/rendering/component/component.test.js
+26
-0
pages/rendering/component/component.uvue
pages/rendering/component/component.uvue
+44
-0
pages/rendering/slots/slots.test.js
pages/rendering/slots/slots.test.js
+1
-3
pages/rendering/template/template.test.js
pages/rendering/template/template.test.js
+7
-3
pages/rendering/template/template.uvue
pages/rendering/template/template.uvue
+2
-3
pages/rendering/unrecognized-component/unrecognized-component.test.js
...ing/unrecognized-component/unrecognized-component.test.js
+11
-0
pages/rendering/unrecognized-component/unrecognized-component.uvue
...dering/unrecognized-component/unrecognized-component.uvue
+3
-0
pages/state/data/data.uvue
pages/state/data/data.uvue
+44
-40
pages/state/methods/methods.uvue
pages/state/methods/methods.uvue
+1
-1
未找到文件。
App.uvue
浏览文件 @
c9e2ba46
...
@@ -3,64 +3,66 @@ import { state, setLifeCycleNum, setAppLaunchPath, setAppShowPath } from './stor
...
@@ -3,64 +3,66 @@ import { state, setLifeCycleNum, setAppLaunchPath, setAppShowPath } from './stor
let firstBackTime = 0
let firstBackTime = 0
export default {
export default {
onLaunch: function (options) {
onLaunch: function (options) {
// 自动化测试
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1000)
setLifeCycleNum(state.lifeCycleNum + 1000)
setAppLaunchPath(options.path)
setAppLaunchPath(options.path)
console.log('App Launch')
console.log('App Launch')
// #ifdef UNI-APP-X && APP-ANDROID
const performance = uni.getPerformance()
const performance = uni.getPerformance()
const observer: PerformanceObserver = performance.createObserver((entryList: PerformanceObserverEntryList) => {
const observer : PerformanceObserver = performance.createObserver((entryList : PerformanceObserverEntryList) => {
console.log(entryList.getEntries())
console.log('observer:entryList.getEntries()')
})
console.log(entryList.getEntries())
observer.observe({
})
entryTypes: ['render', 'navigation'],
observer.observe({
} as PerformanceObserverOptions)
entryTypes: ['render', 'navigation'],
},
} as PerformanceObserverOptions)
onShow: function (options) {
// #endif
// 自动化测试
},
setLifeCycleNum(state.lifeCycleNum + 100)
onShow: function (options) {
setAppShowPath(options.path)
// 自动化测试
console.log('App Show')
setLifeCycleNum(state.lifeCycleNum + 100)
},
setAppShowPath(options.path)
onHide: function () {
console.log('App Show')
// 自动化测试
},
setLifeCycleNum(state.lifeCycleNum - 100)
onHide: function () {
console.log('App Hide')
// 自动化测试
},
setLifeCycleNum(state.lifeCycleNum - 100)
onLastPageBackPress: function () {
console.log('App Hide')
// 自动化测试
},
setLifeCycleNum(state.lifeCycleNum - 1000)
onLastPageBackPress: function () {
console.log('App LastPageBackPress')
// 自动化测试
if (firstBackTime == 0) {
setLifeCycleNum(state.lifeCycleNum - 1000)
uni.showToast({
console.log('App LastPageBackPress')
title: '再按一次退出应用',
if (firstBackTime == 0) {
position: 'bottom',
uni.showToast({
})
title: '再按一次退出应用',
firstBackTime = Date.now()
position: 'bottom',
setTimeout(() => {
})
firstBackTime = 0
firstBackTime = Date.now()
}, 2000)
setTimeout(() => {
} else if (Date.now() - firstBackTime < 2000) {
firstBackTime = 0
firstBackTime = Date.now()
}, 2000)
uni.exit()
} else if (Date.now() - firstBackTime < 2000) {
}
firstBackTime = Date.now()
},
uni.exit()
onExit() {
}
console.log('App Exit')
},
},
onExit() {
methods: {
console.log('App Exit')
checkLaunchPath(): boolean{
},
const HOME_PATH = '/pages/index'
methods: {
if(state.appLaunchPath != HOME_PATH){
checkLaunchPath() : boolean {
return false
const HOME_PATH = '/pages/index'
}
if (state.appLaunchPath != HOME_PATH) {
if(state.appShowPath != HOME_PATH){
return false
return false
}
}
if (state.appShowPath != HOME_PATH) {
return true
return false
}
}
}
return true
}
}
}
}
</script>
</script>
...
...
components/Bar.uvue
0 → 100644
浏览文件 @
c9e2ba46
<template>
<text class="component-bar">this is component Bar</text>
</template>
components/Foo.uvue
0 → 100644
浏览文件 @
c9e2ba46
<template>
<text class="component-foo">this is component Foo</text>
</template>
\ No newline at end of file
jest-setup.js
0 → 100644
浏览文件 @
c9e2ba46
const
{
toMatchImageSnapshot
}
=
require
(
'
jest-image-snapshot
'
)
expect
.
extend
({
toMatchImageSnapshot
})
jest.config.js
浏览文件 @
c9e2ba46
module
.
exports
=
{
module
.
exports
=
{
testTimeout
:
10000
,
testTimeout
:
10000
,
reporters
:
[
reporters
:
[
'
default
'
],
'
default
'
watchPathIgnorePatterns
:
[
'
/node_modules/
'
,
'
/dist/
'
,
'
/.git/
'
],
],
moduleFileExtensions
:
[
'
js
'
,
'
json
'
],
watchPathIgnorePatterns
:
[
'
/node_modules/
'
,
'
/dist/
'
,
'
/.git/
'
],
rootDir
:
__dirname
,
moduleFileExtensions
:
[
'
js
'
,
'
json
'
],
testMatch
:
[
'
<rootDir>/pages/**/**/*.test.js
'
],
rootDir
:
__dirname
,
testPathIgnorePatterns
:
[
'
/node_modules/
'
],
testMatch
:
[
"
<rootDir>/pages/**/**/*.test.js
"
],
setupFilesAfterEnv
:
[
'
<rootDir>/jest-setup.js
'
],
testPathIgnorePatterns
:
[
'
/node_modules/
'
]
}
}
pages.json
浏览文件 @
c9e2ba46
{
{
"pages"
:
[{
"pages"
:
[
{
"path"
:
"pages/index"
,
"path"
:
"pages/index"
,
"style"
:
{
"style"
:
{
"navigationBarTitleText"
:
"hello uvue"
"navigationBarTitleText"
:
"hello uvue"
...
@@ -101,6 +102,12 @@
...
@@ -101,6 +102,12 @@
"navigationBarTitleText"
:
"v-slot"
"navigationBarTitleText"
:
"v-slot"
}
}
},
},
{
"path"
:
"pages/directive/v-html/v-html"
,
"style"
:
{
"navigationBarTitleText"
:
"v-html"
}
},
{
{
"path"
:
"pages/lifecycle/page/page"
,
"path"
:
"pages/lifecycle/page/page"
,
"style"
:
{
"style"
:
{
...
@@ -241,19 +248,22 @@
...
@@ -241,19 +248,22 @@
"navigationBarTitleText"
:
""
,
"navigationBarTitleText"
:
""
,
"enablePullDownRefresh"
:
false
"enablePullDownRefresh"
:
false
}
}
},
{
},
{
"path"
:
"pages/state/props/props"
,
"path"
:
"pages/state/props/props"
,
"style"
:
{
"style"
:
{
"navigationBarTitleText"
:
""
,
"navigationBarTitleText"
:
""
,
"enablePullDownRefresh"
:
false
"enablePullDownRefresh"
:
false
}
}
},
{
},
{
"path"
:
"pages/state/computed/computed"
,
"path"
:
"pages/state/computed/computed"
,
"style"
:
{
"style"
:
{
"navigationBarTitleText"
:
""
,
"navigationBarTitleText"
:
""
,
"enablePullDownRefresh"
:
false
"enablePullDownRefresh"
:
false
}
}
},
{
},
{
"path"
:
"pages/state/watch/watch"
,
"path"
:
"pages/state/watch/watch"
,
"style"
:
{
"style"
:
{
"navigationBarTitleText"
:
""
,
"navigationBarTitleText"
:
""
,
...
@@ -274,12 +284,32 @@
...
@@ -274,12 +284,32 @@
"enablePullDownRefresh"
:
false
"enablePullDownRefresh"
:
false
}
}
},
},
{
"path"
:
"pages/rendering/unrecognized-component/unrecognized-component"
,
"style"
:
{
"navigationBarTitleText"
:
"unrecognized-component"
,
"enablePullDownRefresh"
:
false
}
},
{
"path"
:
"pages/rendering/component/component"
,
"style"
:
{
"navigationBarTitleText"
:
"component"
}
},
{
{
"path"
:
"pages/examples/nested-component-communication/nested-component-communication"
,
"path"
:
"pages/examples/nested-component-communication/nested-component-communication"
,
"style"
:
{
"style"
:
{
"navigationBarTitleText"
:
"嵌套组件通信"
,
"navigationBarTitleText"
:
"嵌套组件通信"
,
"enablePullDownRefresh"
:
false
"enablePullDownRefresh"
:
false
}
}
},
{
"path"
:
"pages/examples/set-custom-child-component-root-node-class/set-custom-child-component-root-node-class"
,
"style"
:
{
"navigationBarTitleText"
:
"自定义组件中使用 class 定制另一个自定义组件根节点样式"
,
"enablePullDownRefresh"
:
false
}
}
}
],
],
"globalStyle"
:
{
"globalStyle"
:
{
...
@@ -297,12 +327,15 @@
...
@@ -297,12 +327,15 @@
}
}
},
},
"uniIdRouter"
:
{},
"uniIdRouter"
:
{},
"condition"
:
{
//模式配置,仅开发期间生效
"condition"
:
{
//模式配置,仅开发期间生效
"current"
:
0
,
//当前激活的模式(list
的索引项)
"current"
:
0
,
//当前激活的模式(list
的索引项)
"list"
:
[{
"list"
:
[
"name"
:
""
,
//模式名称
{
"path"
:
""
,
//启动页面,必选
"name"
:
""
,
//模式名称
"query"
:
""
//启动参数,在页面的onLoad函数里面得到
"path"
:
""
,
//启动页面,必选
}]
"query"
:
""
//启动参数,在页面的onLoad函数里面得到
}
]
}
}
}
}
\ No newline at end of file
pages/component-instance/attrs/child.uvue
浏览文件 @
c9e2ba46
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
</view>
</view>
</template>
</template>
<script>
<script
lang='uts'
>
export default {
export default {
emits: ['result'],
emits: ['result'],
props: {
props: {
...
@@ -25,14 +25,30 @@ export default {
...
@@ -25,14 +25,30 @@ export default {
}
}
},
},
computed: {
computed: {
hasPropsAttrs (): boolean {
hasPropsAttrs(): boolean {
// #ifdef UNI-APP-X && APP-ANDROID
return this.$attrs.has('val')
return this.$attrs.has('val')
// #endif
// #ifdef UNI-APP-X && WEB
return !!this.$attrs['val']
// #endif
},
},
hasEmitsAttr (): boolean {
hasEmitsAttr (): boolean {
// #ifdef UNI-APP-X && APP-ANDROID
return this.$attrs.has('result')
return this.$attrs.has('result')
// #endif
// #ifdef UNI-APP-X && WEB
return !!this.$attrs['result']
// #endif
},
},
hasAttrs (): boolean {
hasAttrs (): boolean {
// #ifdef UNI-APP-X && APP-ANDROID
return this.$attrs.has('class')
return this.$attrs.has('class')
// #endif
// #ifdef UNI-APP-X && WEB
return !!this.$attrs['class']
// #endif
}
}
}
}
}
}
...
...
pages/component-instance/parent/child.uvue
浏览文件 @
c9e2ba46
...
@@ -19,7 +19,11 @@ export default {
...
@@ -19,7 +19,11 @@ export default {
},
},
methods: {
methods: {
testFunction () {
testFunction () {
// #ifdef UNI-APP-X && APP-ANDROID
this.callbackValue = this.$parent!.$callMethod('testFunction') as string
this.callbackValue = this.$parent!.$callMethod('testFunction') as string
// #endif
// TODO: 非 app-android 简单绕过, web 无法通过 this.$parent.functionName 调用父组件 methods 中的方法
this.callbackValue = 'parentFunctionResult'
}
}
}
}
}
}
...
...
pages/component-instance/refs/refs.uvue
浏览文件 @
c9e2ba46
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
</view>
</view>
</template>
</template>
<script>
<script
lang='uts'
>
// import child from './child.uvue'
// import child from './child.uvue'
export default {
export default {
...
@@ -18,7 +18,7 @@ export default {
...
@@ -18,7 +18,7 @@ export default {
}
}
},
},
mounted () {
mounted () {
const nodeRef = this.$refs
.get('node')
const nodeRef = this.$refs
['node']
this.existRef = nodeRef !== null
this.existRef = nodeRef !== null
...
...
pages/component-instance/slots/slot.uvue
浏览文件 @
c9e2ba46
<template>
<template>
<view>
<view>
<slot name="header"></slot>
<slot name="header"></slot>
<slot name="footer"></slot>
<slot name="footer"></slot>
<slot></slot>
<slot></slot>
</view>
</view>
</template>
</template>
<script lang="uts">
<script lang="uts">
export default {
export default {
mounted() {
mounted() {
console.log(this.hasSlots())
console.log(this.hasSlots())
},
},
methods: {
methods: {
hasSlots() : boolean {
hasSlots() : boolean {
const header = this.$slots['header']
const header = this.$slots['header']
const footer = this.$slots['footer']
const footer = this.$slots['footer']
const def = this.$slots['default']
const def = this.$slots['default']
return header !== null && footer !== null && def !== null
return header !== null && footer !== null && def !== null
}
}
}
}
}
}
</script>
</script>
<style scoped>
<style scoped></style>
</style>
\ No newline at end of file
pages/directive/v-html/v-html.test.js
0 → 100644
浏览文件 @
c9e2ba46
const
PAGE_PATH
=
'
/pages/directive/v-html/v-html
'
describe
(
'
v-html
'
,
()
=>
{
let
page
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
'
view
'
)
})
it
(
'
basic
'
,
async
()
=>
{
const
image
=
await
program
.
screenshot
()
expect
(
image
).
toMatchImageSnapshot
()
})
})
\ No newline at end of file
pages/directive/v-html/v-html.uvue
0 → 100644
浏览文件 @
c9e2ba46
<template>
<view v-html="html" />
</template>
<script lang="uts">
export default {
data() {
return {
html: '<p class="p" style="color: red;">hello world!</p>'
}
}
}
</script>
pages/examples/set-custom-child-component-root-node-class/child.uvue
0 → 100644
浏览文件 @
c9e2ba46
<template>
<view>
<button class="btn-child bg-orange">button in child page</button>
</view>
</template>
<style>
.btn-child {
width: 300px;
color: rgb(83, 156, 234);
}
.bg-orange{
background-color: rgb(214, 154, 50);
}
</style>
pages/examples/set-custom-child-component-root-node-class/set-custom-child-component-root-node-class.test.js
0 → 100644
浏览文件 @
c9e2ba46
const
PAGE_PATH
=
'
/pages/examples/set-custom-child-component-root-node-class/set-custom-child-component-root-node-class
'
describe
(
'
自定义组件中使用 class 定制另一个自定义组件根节点样式
'
,
()
=>
{
let
page
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
'
view
'
)
})
it
(
'
screenshot
'
,
async
()
=>
{
const
image
=
await
program
.
screenshot
()
expect
(
image
).
toMatchImageSnapshot
()
})
})
pages/examples/set-custom-child-component-root-node-class/set-custom-child-component-root-node-class.uvue
0 → 100644
浏览文件 @
c9e2ba46
<template>
<view>
<button class="btn-page bg-green">button in parent page</button>
<Child />
</view>
</template>
<script lang='uts'>
import Child from "./child.uvue";
export default {
components: {
Child
}
}
</script>
<style>
.btn-page {
width: 280px;
color: rgb(209, 51, 51);
}
.bg-green{
background-color: rgb(105, 154, 105);
}
</style>
pages/index.uvue
浏览文件 @
c9e2ba46
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
</view>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
<!-- #ifdef APP -->
<!-- #ifdef APP -->
</scroll-view>
</scroll-view>
<!-- #endif -->
<!-- #endif -->
...
@@ -141,6 +141,11 @@
...
@@ -141,6 +141,11 @@
url: 'v-slot',
url: 'v-slot',
enable: true,
enable: true,
},
},
{
name: 'v-html',
url: 'v-html',
enable: true,
},
{
{
name: 'v-pre',
name: 'v-pre',
url: 'v-pre',
url: 'v-pre',
...
@@ -210,10 +215,20 @@
...
@@ -210,10 +215,20 @@
url: 'render',
url: 'render',
enable: false,
enable: false,
},
},
{
{
name: 'slots',
name: 'slots',
url: 'slots',
url: 'slots',
enable: true,
enable: true,
},
{
name: 'component',
url: 'component',
enable: true,
},
{
name: 'unrecognized component',
url: 'unrecognized-component',
enable: true,
},
},
] as PageItem[],
] as PageItem[],
},
},
...
@@ -355,6 +370,10 @@
...
@@ -355,6 +370,10 @@
name: '嵌套组件通信',
name: '嵌套组件通信',
url: 'nested-component-communication',
url: 'nested-component-communication',
enable: true,
enable: true,
},{
name: '自定义组件中使用 class 定制另一个自定义组件根节点样式',
url: 'set-custom-child-component-root-node-class',
enable: true,
}
}
] as PageItem[],
] as PageItem[],
},
},
...
@@ -383,15 +402,15 @@
...
@@ -383,15 +402,15 @@
setLifeCycleNum(num : number) {
setLifeCycleNum(num : number) {
setLifeCycleNum(num)
setLifeCycleNum(num)
},
},
// 自动化测试
// 自动化测试
getLifeCycleNum() : number {
getLifeCycleNum() : number {
return state.lifeCycleNum
return state.lifeCycleNum
},
},
// 自动化测试
// 自动化测试
checkLaunchPath() : boolean {
checkLaunchPath() : boolean {
const app = getApp()
const app = getApp()
return app.checkLaunchPath()
return app.checkLaunchPath()
},
},
},
},
}
}
</script>
</script>
...
...
pages/lifecycle/component/component.test.js
浏览文件 @
c9e2ba46
...
@@ -6,13 +6,14 @@ describe('component-lifecycle', () => {
...
@@ -6,13 +6,14 @@ describe('component-lifecycle', () => {
let
lifeCycleNum
let
lifeCycleNum
beforeAll
(
async
()
=>
{
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
HOME_PATH
)
page
=
await
program
.
reLaunch
(
HOME_PATH
)
await
page
.
waitFor
(
700
)
const
initLifecycleNum
=
0
const
initLifecycleNum
=
0
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
initLifecycleNum
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
initLifecycleNum
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
initLifecycleNum
)
expect
(
lifeCycleNum
).
toBe
(
initLifecycleNum
)
page
=
await
program
.
navigateTo
(
PAGE_PATH
)
page
=
await
program
.
navigateTo
(
PAGE_PATH
)
await
page
.
waitFor
(
10
00
)
await
page
.
waitFor
(
7
00
)
})
})
afterAll
(
async
()
=>
{
afterAll
(
async
()
=>
{
const
resetLifecycleNum
=
1100
const
resetLifecycleNum
=
1100
...
@@ -27,6 +28,7 @@ describe('component-lifecycle', () => {
...
@@ -27,6 +28,7 @@ describe('component-lifecycle', () => {
})
})
it
(
'
beforeUpdate updated
'
,
async
()
=>
{
it
(
'
beforeUpdate updated
'
,
async
()
=>
{
const
component
=
await
page
.
$
(
'
.component-lifecycle
'
)
const
component
=
await
page
.
$
(
'
.component-lifecycle
'
)
console
.
log
(
'
component
'
,
component
)
await
component
.
setData
({
await
component
.
setData
({
title
:
'
component for lifecycle test new title
'
title
:
'
component for lifecycle test new title
'
})
})
...
...
pages/lifecycle/page/page.test.js
浏览文件 @
c9e2ba46
...
@@ -4,80 +4,81 @@ let page
...
@@ -4,80 +4,81 @@ let page
let
lifeCycleNum
let
lifeCycleNum
describe
(
'
app-lifecycle
'
,
()
=>
{
describe
(
'
app-lifecycle
'
,
()
=>
{
it
(
'
onLaunch onShow
'
,
async
()
=>
{
it
(
'
onLaunch onShow
'
,
async
()
=>
{
page
=
await
program
.
reLaunch
(
HOME_PATH
)
page
=
await
program
.
reLaunch
(
HOME_PATH
)
await
page
.
waitFor
(
1000
)
await
page
.
waitFor
(
700
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
1100
)
expect
(
lifeCycleNum
).
toBe
(
1100
)
})
})
it
(
'
onLastPageBackPress
'
,
async
()
=>
{
it
(
'
onLastPageBackPress
'
,
async
()
=>
{
page
=
await
program
.
navigateBack
()
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
await
page
.
waitFor
(
1000
)
page
=
await
program
.
navigateBack
()
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
await
page
.
waitFor
(
700
)
expect
(
lifeCycleNum
).
toBe
(
100
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
100
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
}
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
expect
(
lifeCycleNum
).
toBe
(
0
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
})
expect
(
lifeCycleNum
).
toBe
(
0
)
})
})
})
describe
(
'
page-lifecycle
'
,
()
=>
{
describe
(
'
page-lifecycle
'
,
()
=>
{
afterAll
(
async
()
=>
{
afterAll
(
async
()
=>
{
const
resetLifecycleNum
=
1100
const
resetLifecycleNum
=
1100
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
resetLifecycleNum
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
resetLifecycleNum
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
resetLifecycleNum
)
expect
(
lifeCycleNum
).
toBe
(
resetLifecycleNum
)
})
})
it
(
'
onLoad onShow onReady
'
,
async
()
=>
{
it
(
'
onLoad onShow onReady
'
,
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
10
00
)
await
page
.
waitFor
(
7
00
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
120
)
expect
(
lifeCycleNum
).
toBe
(
120
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
})
it
(
'
onPullDownRefresh
'
,
async
()
=>
{
it
(
'
onPullDownRefresh
'
,
async
()
=>
{
await
page
.
callMethod
(
'
pullDownRefresh
'
)
await
page
.
callMethod
(
'
pullDownRefresh
'
)
await
page
.
waitFor
(
1500
)
await
page
.
waitFor
(
1500
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
10
)
expect
(
lifeCycleNum
).
toBe
(
10
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
})
it
(
'
onPageScroll onReachBottom
'
,
async
()
=>
{
it
(
'
onPageScroll onReachBottom
'
,
async
()
=>
{
await
program
.
pageScrollTo
(
2000
)
await
program
.
pageScrollTo
(
2000
)
const
data
=
await
page
.
data
()
const
data
=
await
page
.
data
()
expect
(
data
.
isScrolled
).
toBe
(
true
)
expect
(
data
.
isScrolled
).
toBe
(
true
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
10
)
expect
(
lifeCycleNum
).
toBe
(
10
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
})
it
(
'
onHide
'
,
async
()
=>
{
it
(
'
onHide
'
,
async
()
=>
{
page
=
await
program
.
navigateTo
(
HOME_PATH
)
page
=
await
program
.
navigateTo
(
HOME_PATH
)
await
page
.
waitFor
(
1000
)
await
page
.
waitFor
(
'
view
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
-
10
)
expect
(
lifeCycleNum
).
toBe
(
-
10
)
page
=
await
program
.
navigateBack
()
page
=
await
program
.
navigateBack
()
await
page
.
waitFor
(
1000
)
await
page
.
waitFor
(
'
view
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
0
)
expect
(
lifeCycleNum
).
toBe
(
0
)
})
})
it
(
'
onUnload
'
,
async
()
=>
{
it
(
'
onUnload
'
,
async
()
=>
{
page
=
await
program
.
redirectTo
(
HOME_PATH
)
page
=
await
program
.
redirectTo
(
HOME_PATH
)
await
page
.
waitFor
(
10
00
)
await
page
.
waitFor
(
7
00
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
-
100
)
expect
(
lifeCycleNum
).
toBe
(
-
100
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
})
it
(
'
onBackPress
'
,
async
()
=>
{
it
(
'
onBackPress
'
,
async
()
=>
{
page
=
await
program
.
navigateTo
(
PAGE_PATH
)
page
=
await
program
.
navigateTo
(
PAGE_PATH
)
await
page
.
waitFor
(
10
00
)
await
page
.
waitFor
(
7
00
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
120
)
expect
(
lifeCycleNum
).
toBe
(
120
)
page
=
await
program
.
navigateBack
()
page
=
await
program
.
navigateBack
()
await
page
.
waitFor
(
1000
)
await
page
.
waitFor
(
'
view
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
10
)
expect
(
lifeCycleNum
).
toBe
(
10
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
})
})
})
\ No newline at end of file
pages/rendering/component/component.test.js
0 → 100644
浏览文件 @
c9e2ba46
describe
(
'
/pages/rendering/component/component
'
,
()
=>
{
let
page
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
'
/pages/rendering/component/component
'
)
await
page
.
waitFor
(
'
view
'
)
})
it
(
'
basic
'
,
async
()
=>
{
let
fooList
=
await
page
.
$$
(
'
.component-foo
'
)
expect
(
fooList
.
length
).
toBe
(
2
)
expect
(
await
fooList
[
0
].
text
()).
toBe
(
'
this is component Foo
'
)
expect
(
await
fooList
[
1
].
text
()).
toBe
(
'
this is component Foo
'
)
let
barList
=
await
page
.
$$
(
'
.component-bar
'
)
expect
(
barList
.
length
).
toBe
(
0
)
await
page
.
callMethod
(
'
changeCurrentComponent
'
)
fooList
=
await
page
.
$$
(
'
.component-foo
'
)
expect
(
fooList
.
length
).
toBe
(
0
)
barList
=
await
page
.
$$
(
'
.component-bar
'
)
expect
(
barList
.
length
).
toBe
(
2
)
expect
(
await
barList
[
0
].
text
()).
toBe
(
'
this is component Bar
'
)
expect
(
await
barList
[
1
].
text
()).
toBe
(
'
this is component Bar
'
)
})
});
\ No newline at end of file
pages/rendering/component/component.uvue
0 → 100644
浏览文件 @
c9e2ba46
<template>
<view class="container">
<component :is="currentComponentStr" />
<component :is="currentComponentInstance" />
<button @click="changeCurrentComponent">change current component</button>
</view>
</template>
<script lang="uts">
import Foo from '../../../components/Foo.uvue'
import Bar from '../../../components/Bar.uvue'
export default {
components: {
Foo,
Bar
},
data() {
return {
currentComponentStr: 'Foo',
currentComponentInstance: Foo,
}
},
methods: {
changeCurrentComponent() {
if (this.currentComponentStr === 'Foo') {
this.currentComponentStr = 'Bar'
this.currentComponentInstance = Bar
} else {
this.currentComponentStr = 'Foo'
this.currentComponentInstance = Foo
}
}
}
}
</script>
<style>
.item {
display: flex;
flex-direction: row;
margin: 15px;
border: #eee solid 1px;
}
</style>
\ No newline at end of file
pages/rendering/slots/slots.test.js
浏览文件 @
c9e2ba46
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
describe
(
'
/pages/rendering/slots/slots
'
,
()
=>
{
describe
(
'
/pages/rendering/slots/slots
'
,
()
=>
{
let
page
;
let
page
;
beforeAll
(
async
()
=>
{
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
'
/pages/rendering/slots/slots
'
)
page
=
await
program
.
reLaunch
(
'
/pages/rendering/slots/slots
'
)
await
page
.
waitFor
(
500
)
await
page
.
waitFor
(
'
view
'
)
});
});
it
(
'
slots
'
,
async
()
=>
{
it
(
'
slots
'
,
async
()
=>
{
expect
.
assertions
(
3
);
expect
.
assertions
(
3
);
const
childEl
=
await
page
.
$
(
'
child
'
);
const
childEl
=
await
page
.
$
(
'
child
'
);
...
...
pages/rendering/template/template.test.js
浏览文件 @
c9e2ba46
...
@@ -4,13 +4,17 @@ describe('/pages/rendering/template/template', () => {
...
@@ -4,13 +4,17 @@ describe('/pages/rendering/template/template', () => {
let
page
let
page
beforeAll
(
async
()
=>
{
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
'
/pages/rendering/template/template
'
)
page
=
await
program
.
reLaunch
(
'
/pages/rendering/template/template
'
)
await
page
.
waitFor
(
500
)
await
page
.
waitFor
(
'
view
'
)
})
})
it
(
'
template
'
,
async
()
=>
{
it
(
'
template
'
,
async
()
=>
{
expect
.
assertions
(
2
);
expect
.
assertions
(
4
);
const
showBtn
=
await
page
.
$
(
'
.show-botton
'
)
const
showBtn
=
await
page
.
$
(
'
.show-botton
'
)
await
showBtn
.
tap
()
await
showBtn
.
tap
()
expect
((
await
page
.
data
()).
isShow
).
toBeFalsy
()
expect
((
await
page
.
data
()).
isShow
).
toBeTruthy
()
const
getTitle
=
await
page
.
$
(
'
.title
'
)
expect
(
await
getTitle
.
text
()).
toBe
(
"
hello
"
)
const
getShow
=
await
page
.
$
(
'
.show-botton
'
)
expect
(
await
getShow
.
text
()).
toBe
(
"
点击隐藏
"
)
expect
((
await
page
.
$$
(
'
.item
'
)).
length
).
toBe
(
2
)
expect
((
await
page
.
$$
(
'
.item
'
)).
length
).
toBe
(
2
)
})
})
});
});
\ No newline at end of file
pages/rendering/template/template.uvue
浏览文件 @
c9e2ba46
<template>
<template>
<view class="container">
<view class="container">
<template v-if="isShow">
<template v-if="isShow">
<view>{{title}}</view>
<view
class="title"
>{{title}}</view>
</template>
</template>
<view class="show-botton" @click="handleShow">{{isShow?'点击隐藏':'点击显示'}}</view>
<view class="show-botton" @click="handleShow">{{isShow?'点击隐藏':'点击显示'}}</view>
<template v-for="(item,index) in list" :key="index">
<template v-for="(item,index) in list" :key="index">
<view class="item">{{index+1}}.{{item.name}}</view>
<view class="item">{{index+1}}.{{item.name}}</view>
</template>
</template>
...
@@ -19,7 +18,7 @@
...
@@ -19,7 +18,7 @@
data() {
data() {
return {
return {
title: "hello",
title: "hello",
isShow:
tru
e,
isShow:
fals
e,
list: [{
list: [{
name: 'foo1'
name: 'foo1'
},
},
...
...
pages/rendering/unrecognized-component/unrecognized-component.test.js
0 → 100644
浏览文件 @
c9e2ba46
describe
(
'
/pages/rendering/unrecognized-component/unrecognized-component
'
,
()
=>
{
let
page
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
'
/pages/rendering/unrecognized-component/unrecognized-component
'
)
await
page
.
waitFor
(
'
text
'
)
})
it
(
'
unrecognized-component should be created as "view"
'
,
async
()
=>
{
const
element
=
await
page
.
$
(
'
text
'
)
expect
(
await
element
.
text
()).
toBe
(
'
text in unrecognized component
'
)
})
});
\ No newline at end of file
pages/rendering/unrecognized-component/unrecognized-component.uvue
0 → 100644
浏览文件 @
c9e2ba46
<template>
<Abc><text>text in unrecognized component</text></Abc>
</template>
pages/state/data/data.uvue
浏览文件 @
c9e2ba46
...
@@ -2,11 +2,11 @@
...
@@ -2,11 +2,11 @@
<view>
<view>
<view class="item">
<view class="item">
<text class="type">数值型数据:</text>
<text class="type">数值型数据:</text>
<text class="value" id="num">{{
num
}}</text>
<text class="value" id="num">{{
num
}}</text>
</view>
</view>
<view class="item">
<view class="item">
<text class="type">字符串型数据:</text>
<text class="type">字符串型数据:</text>
<text class="value" id="str">{{
str
}}</text>
<text class="value" id="str">{{
str
}}</text>
</view>
</view>
<view class="item">
<view class="item">
<text class="type">对象型数据:</text>
<text class="type">对象型数据:</text>
...
@@ -15,64 +15,68 @@
...
@@ -15,64 +15,68 @@
<view class="column">
<view class="column">
<view class="row">
<view class="row">
<text>对象中name的值:</text>
<text>对象中name的值:</text>
<text id="obj_name">{{
obj.name
}}</text>
<text id="obj_name">{{
obj.name
}}</text>
</view>
</view>
<view class="row">
<view class="row">
<text>对象中age的值:</text>
<text>对象中age的值:</text>
<text id="obj_age">{{
obj.age
}}</text>
<text id="obj_age">{{
obj.age
}}</text>
</view>
</view>
</view>
</view>
</view>
</view>
<view class="item">
<view class="item">
<text class="type">数组型数据:</text>
<text class="type">数组型数据:</text>
<text class="value" id="arr">{{
arr
}}</text>
<text class="value" id="arr">{{
arr
}}</text>
<text>通过for循环显示:</text>
<text>通过for循环显示:</text>
<view class="row" v-for="(item,index) in arr" :key="index" style="padding-left: 10px;">
<view
<text>第{{index}}项目的值:</text>
class="row"
<text :id="'arr_'+index">{{item}}</text>
v-for="(item, index) in arr"
:key="index"
style="padding-left: 10px">
<text>第{{ index }}项目的值:</text>
<text :id="'arr_' + index">{{ item }}</text>
</view>
</view>
</view>
</view>
</view>
</view>
</template>
</template>
<script>
<script
lang="uts"
>
type myObj = { name : string, age : number };
type myObj = { name : string, age : number };
// 理论上支持但不支持的写法
// 理论上支持但不支持的写法
// let obj:{ name : string, age : number } = { name: 'John', age: 30 }
// let obj:{ name : string, age : number } = { name: 'John', age: 30 }
export default {
export default {
data() {
data() {
return {
return {
num: 2023 as number,
num: 2023 as number,
str: '我是字符串' as string,
str: '我是字符串' as string,
obj: { name: 'John', age: 30 } as myObj,
obj: { name: 'John', age: 30 } as myObj,
arr: [1, 2, 3, 4, 5, 6, 7] as number[]
arr: [1, 2, 3, 4, 5, 6, 7] as number[]
}
},
onLoad() {
console.log('获取所有 data 中的变量', this.$data);
console.log('获取data中的变量num', this.num);
console.log('获取data中的变量num', this.$data.get('num'));
}
}
},
onLoad() {
console.log('获取所有 data 中的变量',this.$data);
console.log('获取data中的变量num',this.num);
console.log('获取data中的变量num',this.$data['num']);
}
}
}
</script>
</script>
<style>
<style>
.item {
.item {
padding: 5px;
padding: 5px;
flex-direction: row;
flex-direction: row;
flex-wrap: wrap;
flex-wrap: wrap;
position: relative;
position: relative;
border-bottom: 0.1px solid #888;
border-bottom: 0.1px solid #888;
}
}
.row {
.row {
width: 500rpx;
width: 500rpx;
flex-direction: row;
flex-direction: row;
}
}
.column {
.column {
flex-direction: column;
flex-direction: column;
}
}
</style>
</style>
\ No newline at end of file
pages/state/methods/methods.uvue
浏览文件 @
c9e2ba46
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
</view>
</view>
</template>
</template>
<script>
<script
lang='uts'
>
export default {
export default {
data() {
data() {
return {
return {
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录