提交 b457a8b5 编写于 作者: H hdx

feat(callMethod): 新增自动化测试

上级 77ca7f38
...@@ -193,21 +193,27 @@ ...@@ -193,21 +193,27 @@
} }
}, },
{ {
"path": "pages/component-instance/methods/call-uni-element-method", "path": "pages/component-instance/methods/call-method-uni-element",
"style": { "style": {
"navigationBarTitleText": "call-uni-element-method" "navigationBarTitleText": "call-method-uni-element"
} }
}, },
{ {
"path": "pages/component-instance/methods/call-easycom-method", "path": "pages/component-instance/methods/call-method-easycom",
"style": { "style": {
"navigationBarTitleText": "call-easycom-method" "navigationBarTitleText": "call-method-easycom"
} }
}, },
{ {
"path": "pages/component-instance/methods/call-other-method", "path": "pages/component-instance/methods/call-method-easycom-uni-modules",
"style": { "style": {
"navigationBarTitleText": "call-other-method" "navigationBarTitleText": "call-method-easycom-uni-modules"
}
},
{
"path": "pages/component-instance/methods/call-method-other",
"style": {
"navigationBarTitleText": "call-method-other"
} }
}, },
{ {
......
const PAGE_PATH = '/pages/component-instance/methods/call-method-easycom-uni-modules'
describe('call-method-easycom-uni-modules', () => {
let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500)
})
it('callMethodTest', async () => {
const title = Date.now() + ''
const result = await page.callMethod('callMethodTest', title)
expect(result).toBe(title)
})
})
\ No newline at end of file
<template>
<view>
<call-easy-method-uni-modules ref="callEasyMethod1"></call-easy-method-uni-modules>
</view>
</template>
<script>
export default {
data() {
return {
$callEasyMethod1: null as CallEasyMethodUniModulesComponentPublicInstance | null
}
},
onReady() {
// 通过组件 ref 属性获取组件实例, 组件标签名首字母大写,驼峰+ComponentPublicInstance
this.$callEasyMethod1 = this.$refs['callEasyMethod1'] as CallEasyMethodUniModulesComponentPublicInstance;
},
methods: {
callMethod1() {
// 调用组件的 foo1 方法
this.$callEasyMethod1!.foo1();
},
callMethod2() {
// 调用组件的 foo2 方法并传递 1个参数
this.$callEasyMethod1!.foo2(Date.now());
},
callMethod3() {
// 调用组件的 foo3 方法并传递 2个参数
this.$callEasyMethod1!.foo3(Date.now(), Date.now());
},
callMethod4() {
// 调用组件的 foo4 方法并传递 callback
this.$callEasyMethod1!.foo4(() => {
console.log('callback')
});
},
callMethod5() {
// 注意: 返回值可能为 null,当前例子一定不为空,所以加了 !
const result = this.$callEasyMethod1!.foo5('string1')! as string;
console.log(result); // string1
},
callMethodTest(text: string): string | null {
const result = this.$callEasyMethod1!.foo5(text)! as string;
return result;
},
}
}
</script>
\ No newline at end of file
const PAGE_PATH = '/pages/component-instance/methods/call-method-easycom'
describe('call-method-easycom', () => {
let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500)
})
it('callMethodTest', async () => {
const title = Date.now() + ''
const result = await page.callMethod('callMethodTest', title)
expect(result).toBe(title)
})
})
\ No newline at end of file
...@@ -39,6 +39,10 @@ ...@@ -39,6 +39,10 @@
const result = this.$callEasyMethod1!.foo5('string1')! as string; const result = this.$callEasyMethod1!.foo5('string1')! as string;
console.log(result); // string1 console.log(result); // string1
}, },
callMethodTest(text: string): string | null {
const result = this.$callEasyMethod1!.foo5(text)! as string;
return result;
},
} }
} }
</script> </script>
\ No newline at end of file
const PAGE_PATH = '/pages/component-instance/methods/call-method-other'
describe('call-method-other', () => {
let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500)
})
it('callMethodTest', async () => {
const title = Date.now() + ''
const result = await page.callMethod('callMethodTest', title)
expect(result).toBe(title)
})
})
\ No newline at end of file
...@@ -49,6 +49,10 @@ ...@@ -49,6 +49,10 @@
const result = this.$component1!.$callMethod('foo5', 'string1')! as string; const result = this.$component1!.$callMethod('foo5', 'string1')! as string;
console.log(result); // string1 console.log(result); // string1
}, },
callMethodTest(text: string): string | null {
const result = this.$component1!.$callMethod('foo5', text)! as string;
return result;
},
} }
} }
</script> </script>
\ No newline at end of file
const PAGE_PATH = '/pages/component-instance/methods/call-method-uni-element'
describe('call-method-uni-element', () => {
let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500)
})
it('callMethodTest', async () => {
const title = Date.now() + ''
const result = await page.callMethod('callMethodTest', title)
expect(result).toBe(title)
})
})
\ No newline at end of file
...@@ -20,7 +20,12 @@ ...@@ -20,7 +20,12 @@
// 设置组件的 value 属性 // 设置组件的 value 属性
this.$slider1!.value = 80; this.$slider1!.value = 80;
return true; return true;
} },
callMethodTest(text: string): string | null {
this.$slider1!.setAttribute('value', text);
const result = this.$slider1!.getAttribute('value')! as string;
return result;
},
} }
} }
</script> </script>
\ No newline at end of file
...@@ -288,18 +288,23 @@ ...@@ -288,18 +288,23 @@
enable: true, enable: true,
}, },
{ {
name: 'call-uni-element-method', name: 'call-method-uni-element',
url: 'methods/call-uni-element-method', url: 'methods/call-method-uni-element',
enable: true, enable: true,
}, },
{ {
name: 'call-easycom-method', name: 'call-method-easycom',
url: 'methods/call-easycom-method', url: 'methods/call-method-easycom',
enable: true, enable: true,
}, },
{ {
name: 'call-other-method', name: 'call-method-easycom-uni-modules',
url: 'methods/call-other-method', url: 'methods/call-method-easycom-uni-modules',
enable: true,
},
{
name: 'call-method-other',
url: 'methods/call-method-other',
enable: true, enable: true,
}, },
] as PageItem[], ] as PageItem[],
......
<template>
<view></view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
foo1() {
},
foo2(date1 : number) {
},
foo3(date1 : number, date2 : number) {
},
foo4(callback : (() => void)) {
callback()
},
foo5(text1 : string) : any | null {
return text1
}
}
}
</script>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册