提交 c9e2ba46 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

Merge branch 'master' into dev

...@@ -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>
......
<template>
<text class="component-bar">this is component Bar</text>
</template>
<template>
<text class="component-foo">this is component Foo</text>
</template>
\ No newline at end of file
const { toMatchImageSnapshot } = require('jest-image-snapshot')
expect.extend({ toMatchImageSnapshot })
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": [{ "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
...@@ -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
} }
} }
} }
......
...@@ -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'
} }
} }
} }
......
...@@ -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
......
<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
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
<template>
<view v-html="html" />
</template>
<script lang="uts">
export default {
data() {
return {
html: '<p class="p" style="color: red;">hello world!</p>'
}
}
}
</script>
<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>
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()
})
})
<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>
...@@ -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>
......
...@@ -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(1000) await page.waitFor(700)
}) })
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'
}) })
......
...@@ -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(1000) await page.waitFor(700)
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(1000) await page.waitFor(700)
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(1000) await page.waitFor(700)
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
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
<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
// 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');
......
...@@ -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
<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: true, isShow: false,
list: [{ list: [{
name: 'foo1' name: 'foo1'
}, },
......
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
<template>
<Abc><text>text in unrecognized component</text></Abc>
</template>
...@@ -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
...@@ -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.
先完成此消息的编辑!
想要评论请 注册