提交 39686008 编写于 作者: 辛宝Otto's avatar 辛宝Otto 🥊

feat: 测试 uni.createSelectorQuery 传递 node/fields

上级 8e917c1b
...@@ -74,6 +74,23 @@ describe('nodes-info', () => { ...@@ -74,6 +74,23 @@ describe('nodes-info', () => {
}) */ }) */
// #endif // #endif
it('test filelds', async () => {
if (process.env.uniTestPlatformInfo.startsWith('web')) {
expect(true).toBe(true)
} else {
const pageData = await page.data()
expect(pageData.fieldsResultContainNode).toBe(true)
}
})
it('test node', async () => {
if (process.env.uniTestPlatformInfo.startsWith('web')) {
expect(true).toBe(true)
} else {
const pageData = await page.data()
expect(pageData.nodeResultContainNode).toBe(true)
}
})
}) })
async function getRootNode(selector) { async function getRootNode(selector) {
......
...@@ -43,6 +43,15 @@ ...@@ -43,6 +43,15 @@
<multi-child ref="multi-child" id="multi-child"></multi-child> <multi-child ref="multi-child" id="multi-child"></multi-child>
<text>子组件多根节点(仅测试,用于验证查询是否超出范围)</text> <text>子组件多根节点(仅测试,用于验证查询是否超出范围)</text>
<multi-child id="multi-child-2"></multi-child> <multi-child id="multi-child-2"></multi-child>
<view>
<text>测试.fields</text>
<text>{{fieldsResultContainNode}}</text>
</view>
<view>
<text>测试.node</text>
<text>{{nodeResultContainNode}}</text>
</view>
<canvas id="canvas1"></canvas>
</view> </view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
</scroll-view> </scroll-view>
...@@ -78,12 +87,17 @@ ...@@ -78,12 +87,17 @@
// TODO // TODO
selectCount: 0, selectCount: 0,
selectAllCount: 0, selectAllCount: 0,
fieldsResultContainNode: false,
nodeResultContainNode: false
} }
}, },
onReady() { onReady() {
const instance2 = (this.$refs['multi-child'] as ComponentPublicInstance) const instance2 = (this.$refs['multi-child'] as ComponentPublicInstance)
this.selectCount = instance2.$data['selectCount'] as Number this.selectCount = instance2.$data['selectCount'] as Number
this.selectAllCount = instance2.$data['selectAllCount'] as Number this.selectAllCount = instance2.$data['selectAllCount'] as Number
this.testFields()
this.testNode()
}, },
onResize() { onResize() {
//供自动化测试使用 //供自动化测试使用
...@@ -142,7 +156,32 @@ ...@@ -142,7 +156,32 @@
} as NodeInfoType) } as NodeInfoType)
}) })
}) })
} },
// test .fields
testFields() {
uni.createSelectorQuery().select('.rect1').fields({
node: true
} as NodeField, (ret) => {
const isElement = (ret as NodeInfo).node instanceof UniElement
if(isElement){
this.fieldsResultContainNode = true
} else {
this.fieldsResultContainNode = false
}
}).exec()
},
// test .node
testNode() {
uni.createSelectorQuery().select('#canvas1').node((ret) => {
const isElement = (ret as NodeInfo).node instanceof UniElement
const isCanvasElement = ((ret as NodeInfo).node as UniCanvasElement).tagName == 'CANVAS'
if(isElement && isCanvasElement){
this.nodeResultContainNode = true
} else {
this.nodeResultContainNode = false
}
}).exec()
},
} }
} }
</script> </script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册