diff --git a/pages/API/event-bus/event-bus.test.js b/pages/API/event-bus/event-bus.test.js index b0b61183c954af4b858f190dc15ec5c83c9cf74d..bf58ee9d91079f3799bd60d6a841817e2524730a 100644 --- a/pages/API/event-bus/event-bus.test.js +++ b/pages/API/event-bus/event-bus.test.js @@ -52,21 +52,21 @@ describe('event-bus', () => { expect(l3).toBe(0) }) - // it('off-all', async () => { - // await page.callMethod('clear') - // await page.callMethod('on') - // await page.callMethod('on2') - // await page.callMethod('emit') - // const l1 = (await page.data()).log.length - // expect(l1).toBe(2) + it('off-all', async () => { + await page.callMethod('clear') + await page.callMethod('on') + await page.callMethod('on2') + await page.callMethod('emit') + const l1 = (await page.data()).log.length + expect(l1).toBe(2) - // await page.callMethod('clear') - // const l2 = (await page.data()).log.length - // expect(l2).toBe(0) + await page.callMethod('clear') + const l2 = (await page.data()).log.length + expect(l2).toBe(0) - // await page.callMethod('offAll') - // await page.callMethod('emit') - // const l3 = (await page.data()).log.length - // expect(l3).toBe(0) - // }) + await page.callMethod('offAll') + 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 index b470400e48ae066d4ab2d22d6af1fa93a059bf9b..a34651a7515916e25f6a8f7027bdf76bed7affd3 100644 --- a/pages/API/event-bus/event-bus.uvue +++ b/pages/API/event-bus/event-bus.uvue @@ -48,8 +48,7 @@ uni.$off('test', this.fn) }, offAll() { - // TODO 第二个参数为可选,后续优化后可不传递 - //uni.$off('test', null) + uni.$off('test') }, emit() { uni.$emit('test', 'msg:' + Date.now())