提交 129bee85 编写于 作者: Q qiang

feat: add event bus test

上级 647b2858
...@@ -561,6 +561,12 @@ ...@@ -561,6 +561,12 @@
"navigationBarTitleText": "pageScrollTo", "navigationBarTitleText": "pageScrollTo",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, {
"path": "pages/API/event-bus/event-bus",
"style": {
"navigationBarTitleText": "event-bus",
"enablePullDownRefresh": false
}
}, { }, {
"path": "pages/template/drop-card/drop-card", "path": "pages/template/drop-card/drop-card",
"style": { "style": {
......
const PAGE_PATH = '/pages/API/event-bus/event-bus'
describe('event-bus', () => {
let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500)
})
it('on', async () => {
await page.callMethod('clear')
await page.callMethod('on')
await page.callMethod('emit')
const l1 = (await page.data()).log.length
expect(l1).toBe(1)
await page.callMethod('clear')
await page.callMethod('emit')
const l2 = (await page.data()).log.length
expect(l2).toBe(1)
await page.callMethod('clear')
await page.callMethod('on')
await page.callMethod('emit')
const l3 = (await page.data()).log.length
expect(l3).toBe(2)
await page.callMethod('clear')
await page.callMethod('off')
await page.callMethod('emit')
const l4 = (await page.data()).log.length
expect(l4).toBe(1)
await page.callMethod('clear')
await page.callMethod('off')
await page.callMethod('emit')
const l5 = (await page.data()).log.length
expect(l5).toBe(0)
})
it('once', async () => {
await page.callMethod('clear')
await page.callMethod('once')
await page.callMethod('emit')
const l1 = (await page.data()).log.length
expect(l1).toBe(1)
await page.callMethod('clear')
await page.callMethod('emit')
const l2 = (await page.data()).log.length
expect(l2).toBe(0)
await page.callMethod('clear')
await page.callMethod('once')
await page.callMethod('off')
await page.callMethod('emit')
const l3 = (await page.data()).log.length
expect(l3).toBe(0)
})
})
<template>
<view>
<button @click="on">开始监听</button>
<button @click="once">监听一次</button>
<button @click="off">取消监听</button>
<button @click="emit">触发监听</button>
<button @click="clear">清空消息</button>
<view class="box">
<view>收到的消息:</view>
<view>
<view v-for="(item, index) in log" :key="index">{{ item }}</view>
</view>
</view>
</view>
</template>
<script lang="ts">
export default {
data() {
return {
log: [] as string[]
}
},
methods: {
fn(res: string) {
this.log.push(res)
},
on() {
uni.$on('test', this.fn)
},
once() {
uni.$once('test', this.fn)
},
off() {
uni.$off('test', this.fn)
},
emit() {
uni.$emit('test', 'msg:' + Date.now())
},
clear() {
this.log.length = 0
}
}
}
</script>
<style>
.box {
padding: 10px;
}
</style>
\ No newline at end of file
...@@ -456,6 +456,14 @@ ...@@ -456,6 +456,14 @@
url: "/platforms/app-plus/push/push", url: "/platforms/app-plus/push/push",
}, },
] as Page[], ] as Page[],
},
{
id: "event-bus",
name: "event-bus",
open: false,
enable: true,
url: "event-bus",
pages: [] as Page[],
}, },
//#endif //#endif
] as ListItem[], ] as ListItem[],
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册