提交 bca57a74 编写于 作者: H hdx

feat(nodes-info): 补充子组件的 mounted 生命周期测试

上级 b54f8fe6
<template>
<view class="selector-query-child-view">
<text class="selector-query-child-text">selector-query-child</text>
</view>
</template>
<script>
export default {
data() {
return {
top: 0
}
},
mounted() {
uni.createSelectorQuery().in(this).select('.selector-query-child-view').boundingClientRect().exec((ret) => {
if (ret.length == 1) {
const nodeInfo = ret[0] as NodeInfo;
this.top = nodeInfo.top!
}
})
}
}
</script>
<style>
.selector-query-child-view {
margin-top: 15px;
}
</style>
...@@ -54,6 +54,11 @@ describe('nodes-info', () => { ...@@ -54,6 +54,11 @@ describe('nodes-info', () => {
expect(Math.round(nodeInfo2.width)).toBe(RECT_WIDTH) expect(Math.round(nodeInfo2.width)).toBe(RECT_WIDTH)
expect(Math.round(nodeInfo2.height)).toBe(RECT_HEIGHT) expect(Math.round(nodeInfo2.height)).toBe(RECT_HEIGHT)
}) })
it('get-node-info-child', async () => {
const child = await page.$('.node-child')
const childData = await child.data()
expect(childData.top > 100).toBe(true)
})
// #ifdef APP // #ifdef APP
//检测onResize获取BoundingClientRect信息是否有效 //检测onResize获取BoundingClientRect信息是否有效
......
...@@ -34,11 +34,14 @@ ...@@ -34,11 +34,14 @@
<text class="node-info-item-v">{{nodeInfo.height}}</text> <text class="node-info-item-v">{{nodeInfo.height}}</text>
</view> </view>
</view> </view>
<node-child class="node-child"></node-child>
</view> </view>
</view> </view>
</template> </template>
<script> <script>
import nodeChild from './nodes-info-child.uvue'
type NodeInfoType = { type NodeInfoType = {
left : number | null, left : number | null,
top : number | null, top : number | null,
...@@ -49,6 +52,9 @@ ...@@ -49,6 +52,9 @@
} }
export default { export default {
components: {
nodeChild
},
data() { data() {
return { return {
title: 'createSelectorQuery', title: 'createSelectorQuery',
...@@ -71,7 +77,7 @@ ...@@ -71,7 +77,7 @@
}, },
methods: { methods: {
// 仅用于自动化测试 // 仅用于自动化测试
getRootNodeInfo(selector: string) { getRootNodeInfo(selector : string) {
uni.createSelectorQuery().select(selector).boundingClientRect().exec((ret) => { uni.createSelectorQuery().select(selector).boundingClientRect().exec((ret) => {
if (ret.length == 1) { if (ret.length == 1) {
const nodeInfo = ret[0] as NodeInfo; const nodeInfo = ret[0] as NodeInfo;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册