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