Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
39686008
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5995
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
39686008
编写于
8月 02, 2024
作者:
辛宝Otto
🥊
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 测试 uni.createSelectorQuery 传递 node/fields
上级
8e917c1b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
66 addition
and
10 deletion
+66
-10
pages/API/create-selector-query/create-selector-query.test.js
...s/API/create-selector-query/create-selector-query.test.js
+24
-7
pages/API/create-selector-query/create-selector-query.uvue
pages/API/create-selector-query/create-selector-query.uvue
+42
-3
未找到文件。
pages/API/create-selector-query/create-selector-query.test.js
浏览文件 @
39686008
...
@@ -58,12 +58,12 @@ describe('nodes-info', () => {
...
@@ -58,12 +58,12 @@ describe('nodes-info', () => {
const
child
=
await
page
.
$
(
'
.node-child
'
)
const
child
=
await
page
.
$
(
'
.node-child
'
)
const
childData
=
await
child
.
data
()
const
childData
=
await
child
.
data
()
expect
(
childData
.
top
>
100
).
toBe
(
true
)
expect
(
childData
.
top
>
100
).
toBe
(
true
)
})
})
it
(
'
multi-child
'
,
async
()
=>
{
it
(
'
multi-child
'
,
async
()
=>
{
const
pageData
=
await
page
.
data
()
const
pageData
=
await
page
.
data
()
expect
(
pageData
.
selectCount
).
toBe
(
1
)
expect
(
pageData
.
selectCount
).
toBe
(
1
)
expect
(
pageData
.
selectAllCount
).
toBe
(
2
)
expect
(
pageData
.
selectAllCount
).
toBe
(
2
)
})
})
// #ifdef APP
// #ifdef APP
...
@@ -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
)
{
...
@@ -89,4 +106,4 @@ async function getRootNode(selector) {
...
@@ -89,4 +106,4 @@ async function getRootNode(selector) {
const
data
=
await
page
.
data
()
const
data
=
await
page
.
data
()
expect
(
data
.
rootNodeInfo
!=
null
).
toBe
(
true
)
expect
(
data
.
rootNodeInfo
!=
null
).
toBe
(
true
)
}
}
pages/API/create-selector-query/create-selector-query.uvue
浏览文件 @
39686008
...
@@ -42,7 +42,16 @@
...
@@ -42,7 +42,16 @@
<text>子组件多根节点</text>
<text>子组件多根节点</text>
<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>
...
@@ -77,13 +86,18 @@
...
@@ -77,13 +86,18 @@
// resizeRectValid: false
// resizeRectValid: false
// 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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录