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

feat(eventBus): 补充返回 id 示例及测试

上级 b94d666a
...@@ -77,4 +77,13 @@ describe('event-bus', () => { ...@@ -77,4 +77,13 @@ describe('event-bus', () => {
const l3 = (await page.data()).log.length const l3 = (await page.data()).log.length
expect(l3).toBe(0) expect(l3).toBe(0)
}) })
it('test return id', async () => {
await page.callMethod('clear')
expect((await page.data()).log.length).toBe(0)
await page.callMethod('testReturnId')
const logs = await page.data('log')
expect(logs.length).toBe(2)
expect(logs[0]).toBe('触发 test-return-id $on fn')
expect(logs[1]).toBe('触发 test-return-id $once fn')
})
}) })
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
<text>接收到的 obj 参数:</text> <text>接收到的 obj 参数:</text>
<text>{{JSON.stringify(objArg)}}</text> <text>{{JSON.stringify(objArg)}}</text>
</view> </view>
<button @click="testReturnId">测试返回 id</button>
</view> </view>
</view> </view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
...@@ -71,6 +72,19 @@ ...@@ -71,6 +72,19 @@
clear() { clear() {
this.log.length = 0 this.log.length = 0
}, },
testReturnId(){
const id1 = uni.$on('test-return-id', this.fn)
uni.$emit('test-return-id', '触发 test-return-id $on fn')
uni.$off('test-return-id', id1)
uni.$emit('test-return-id', '触发 test-return-id $on fn')
uni.$once('test-return-id', this.fn)
uni.$emit('test-return-id', '触发 test-return-id $once fn')
uni.$emit('test-return-id', '触发 test-return-id $once fn')
const id2 = uni.$once('test-id', this.fn)
uni.$off('test-return-id', id2)
uni.$emit('test-return-id', '触发 test-return-id $once fn')
}
}, },
} }
</script> </script>
...@@ -79,4 +93,4 @@ ...@@ -79,4 +93,4 @@
.box { .box {
padding: 10px; padding: 10px;
} }
</style> </style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册