提交 c93d4f13 编写于 作者: F fxy060608 提交者: DCloud-WZF

feat: 添加 自定义easycom规则组件类型测试 #9386

上级 7060f33b
<template>
<view>{{result}}</view>
</template>
<script>
export default {
data() {
return {
result: ''
}
},
methods: {
foo() : string {
this.result = "custom foo"
return this.result
}
}
}
</script>
\ No newline at end of file
......@@ -902,6 +902,11 @@
"navigationBarBackgroundColor": "#007AFF"
}
},
"easycom": {
"custom": {
"custom-(.*)": "@/components/custom-$1.uvue"
}
},
"uniIdRouter": {},
"condition": {
"current": 0,
......
<template>
<view>
<call-easy-method ref="callEasyMethod1"></call-easy-method>
<custom-call-easy-method ref="customCallEasyMethod1"></custom-call-easy-method>
</view>
</template>
<script setup lang="uts">
const callEasyMethod1 = ref<CallEasyMethodComponentPublicInstance | null>(null)
const customCallEasyMethod1 = ref<CustomCallEasyMethodComponentPublicInstance | null>(null)
const callMethod = () => {
// 调用组件的 foo 方法
customCallEasyMethod1.value?.foo?.()
}
const callMethod1 = () => {
// 调用组件的 foo1 方法
......@@ -40,6 +47,11 @@ const callMethodTest = (text: string): string | null => {
return result
}
const callCustomMethodTest = (): string | null => {
const result = customCallEasyMethod1.value?.foo?.() as string
return result
}
const delay = (): Promise<string> =>
new Promise((resolve, _) => {
setTimeout(() => {
......@@ -48,6 +60,7 @@ const delay = (): Promise<string> =>
})
const call = async (): Promise<void> => {
callMethod()
callMethod1()
await delay()
callMethod2()
......@@ -64,6 +77,7 @@ onReady(() => {
})
defineExpose({
callMethodTest
callMethodTest,
callCustomMethodTest
})
</script>
\ No newline at end of file
<template>
<view>
<call-easy-method ref="callEasyMethod1"></call-easy-method>
<custom-call-easy-method ref="customCallEasyMethod1"></custom-call-easy-method>
</view>
</template>
......@@ -15,16 +16,19 @@ const delay = (): Promise<string> =>
export default {
data() {
return {
callEasyMethod1: null as CallEasyMethodComponentPublicInstance | null
callEasyMethod1: null as CallEasyMethodComponentPublicInstance | null,
customCallEasyMethod1: null as CustomCallEasyMethodComponentPublicInstance | null,
}
},
onReady() {
// 通过组件 ref 属性获取组件实例, 组件标签名首字母大写,驼峰+ComponentPublicInstance
this.callEasyMethod1 = this.$refs['callEasyMethod1'] as CallEasyMethodComponentPublicInstance
this.customCallEasyMethod1 = this.$refs['customCallEasyMethod1'] as CustomCallEasyMethodComponentPublicInstance
this.call()
},
methods: {
async call(): Promise<void> {
this.callCustomMethod()
this.callMethod1()
await delay()
this.callMethod2()
......@@ -61,7 +65,15 @@ export default {
callMethodTest(text: string): string | null {
const result = this.callEasyMethod1?.foo5?.(text) as string
return result
}
},
callCustomMethod() {
// 调用组件的 foo 方法
this.customCallEasyMethod1?.foo?.()
},
callCustomMethodTest(): string | null {
const result = this.customCallEasyMethod1?.foo?.() as string
return result
},
}
}
</script>
\ No newline at end of file
......@@ -10,6 +10,8 @@ describe('call-method-easycom', () => {
const title = Date.now() + ''
const result = await page.callMethod('callMethodTest', title)
expect(result).toBe(title)
const customResult = await page.callMethod('callCustomMethodTest')
expect(customResult).toBe('custom foo')
})
it('callMethodTest Composition API', async () => {
......@@ -18,5 +20,7 @@ describe('call-method-easycom', () => {
const title = Date.now() + ''
const result = await page.callMethod('callMethodTest', title)
expect(result).toBe(title)
const customResult = await page.callMethod('callCustomMethodTest')
expect(customResult).toBe('custom foo')
})
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册