event-bus.test.js 1.6 KB
Newer Older
Q
qiang 已提交
1 2 3 4 5 6
const PAGE_PATH = '/pages/API/event-bus/event-bus'

describe('event-bus', () => {
  let page
  beforeAll(async () => {
    page = await program.reLaunch(PAGE_PATH)
7
    await page.waitFor('view')
Q
qiang 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
  })

  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)
  })
})