提交 04f2f1d4 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

refactor(component instance): emit function

上级 6c03fb1e
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<view class="page"> <view class="page">
<view class="row"> <view class="row">
<text>子组件传的参数</text> <text>子组件传的参数</text>
<text> <text id="value">
{{ value }} {{ value }}
</text> </text>
</view> </view>
...@@ -13,18 +13,11 @@ ...@@ -13,18 +13,11 @@
<script setup lang="uts"> <script setup lang="uts">
import child from './child-composition.uvue' import child from './child-composition.uvue'
defineOptions({ const value = ref('')
data() {
return { const callback = (str: string) => {
value: '' value.value = str
} }
},
methods: {
callback(str: string) {
this.value = str
}
}
})
</script> </script>
<style> <style>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<view class="page"> <view class="page">
<view class="row"> <view class="row">
<text>子组件传的参数</text> <text>子组件传的参数</text>
<text> <text id="value">
{{ value }} {{ value }}
</text> </text>
</view> </view>
......
...@@ -2,30 +2,23 @@ const PAGE_PATH = '/pages/component-instance/emit-function/emit-function-options ...@@ -2,30 +2,23 @@ const PAGE_PATH = '/pages/component-instance/emit-function/emit-function-options
const PAGE_COMPOSITION_PATH = '/pages/component-instance/emit-function/emit-function-composition' const PAGE_COMPOSITION_PATH = '/pages/component-instance/emit-function/emit-function-composition'
describe('$emit()', () => { describe('$emit()', () => {
let page const test = async (path) => {
it('$emit() 选项式 API 事件生效', async () => { const page = await program.reLaunch(path)
page = await program.reLaunch(PAGE_PATH) await page.waitFor('view')
await page.waitFor(500) const valueText = await page.$('#value')
const beforeValue = await page.data('value') const beforeValue = await valueText.text()
const btn = await page.$('.call-parent-btn')
btn.tap()
const afterValue = await page.data('value') const btn = await page.$('.call-parent-btn')
await btn.tap()
const afterValue = await valueText.text()
expect(beforeValue).not.toBe(afterValue) expect(beforeValue).not.toBe(afterValue)
}
it('$emit() 选项式 API 事件生效', async () => {
await test(PAGE_PATH)
}) })
it('$emit() 组合式 API 事件生效', async () => { it('$emit() 组合式 API 事件生效', async () => {
page = await program.reLaunch(PAGE_COMPOSITION_PATH) await test(PAGE_COMPOSITION_PATH)
await page.waitFor(500)
const beforeValue = await page.data('value')
const btn = await page.$('.call-parent-btn')
btn.tap()
const afterValue = await page.data('value')
expect(beforeValue).not.toBe(afterValue)
}) })
}) })
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册