From 129bee857c97a84c71143ec990285d14ab9ffce5 Mon Sep 17 00:00:00 2001 From: qiang Date: Fri, 7 Jul 2023 19:58:50 +0800 Subject: [PATCH] feat: add event bus test --- pages.json | 6 +++ pages/API/event-bus/event-bus.test.js | 54 +++++++++++++++++++++++++++ pages/API/event-bus/event-bus.uvue | 51 +++++++++++++++++++++++++ pages/tabBar/API.uvue | 8 ++++ 4 files changed, 119 insertions(+) create mode 100644 pages/API/event-bus/event-bus.test.js create mode 100644 pages/API/event-bus/event-bus.uvue diff --git a/pages.json b/pages.json index c77c0e49..d5048156 100644 --- a/pages.json +++ b/pages.json @@ -561,6 +561,12 @@ "navigationBarTitleText": "pageScrollTo", "enablePullDownRefresh": false } + }, { + "path": "pages/API/event-bus/event-bus", + "style": { + "navigationBarTitleText": "event-bus", + "enablePullDownRefresh": false + } }, { "path": "pages/template/drop-card/drop-card", "style": { diff --git a/pages/API/event-bus/event-bus.test.js b/pages/API/event-bus/event-bus.test.js new file mode 100644 index 00000000..35d3e366 --- /dev/null +++ b/pages/API/event-bus/event-bus.test.js @@ -0,0 +1,54 @@ +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) + }) +}) diff --git a/pages/API/event-bus/event-bus.uvue b/pages/API/event-bus/event-bus.uvue new file mode 100644 index 00000000..6abf9944 --- /dev/null +++ b/pages/API/event-bus/event-bus.uvue @@ -0,0 +1,51 @@ + + + + + \ No newline at end of file diff --git a/pages/tabBar/API.uvue b/pages/tabBar/API.uvue index 5bdca3fa..1df2ac71 100644 --- a/pages/tabBar/API.uvue +++ b/pages/tabBar/API.uvue @@ -456,6 +456,14 @@ url: "/platforms/app-plus/push/push", }, ] as Page[], + }, + { + id: "event-bus", + name: "event-bus", + open: false, + enable: true, + url: "event-bus", + pages: [] as Page[], }, //#endif ] as ListItem[], -- GitLab