提交 886f8c9e 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

refactor(component instance): emit function

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