navigator.test.js 4.0 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3 4 5 6 7 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
jest.setTimeout(40000)
const CURRENT_PAGE_PATH = '/pages/API/navigator/navigator'
const HOME_PAGE_PATH = '/pages/tabBar/component'

describe('navigator', () => {
  let page
  let lifeCycleNum
  it('reLaunch', async () => {
    page = await program.navigateTo(CURRENT_PAGE_PATH)
    await page.waitFor(1000)
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('reLaunch')
    await new Promise((resolve) => {
      setTimeout(resolve, 1000)
    })
    page = await program.navigateTo(CURRENT_PAGE_PATH)
    await page.waitFor(1000)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(2)
  })

  it('navigateTo', async () => {
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('navigateTo')
    await new Promise((resolve) => {
      setTimeout(resolve, 1000)
    })
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(2)
    page = await program.navigateBack()
    await page.waitFor(1000)
  })

  it('navigateTo error page', async () => {
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('navigateToErrorPage')
    await page.waitFor(1000)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(2)
  })

  it('navigateTo debounce', async () => {
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('navigateToDebounce')
    await new Promise((resolve) => {
      setTimeout(resolve, 1000)
    })
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(4)
    page = await program.navigateBack()
    await page.waitFor(1000)
  })

DCloud-WZF's avatar
DCloud-WZF 已提交
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
  it('navigateTo relative path', async () => {
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('navigateToRelativePath1')
    page = await program.navigateBack()
    await page.waitFor(1000)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(2)
    await page.waitFor(1000)
  })

  it('navigateTo relative path ./', async () => {
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('navigateToRelativePath2')
    page = await program.navigateBack()
    await page.waitFor(1000)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(2)
    await page.waitFor(1000)
  })

  it('navigateTo relative path ../', async () => {
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('navigateToRelativePath3')
    page = await program.navigateBack()
    await page.waitFor(1000)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(2)
    await page.waitFor(1000)
  })

DCloud-WZF's avatar
DCloud-WZF 已提交
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
  it('navigateBack', async () => {
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('navigateBack')
    await new Promise((resolve) => {
      setTimeout(resolve, 1000)
    })
    page = await program.navigateTo(CURRENT_PAGE_PATH)
    await page.waitFor(1000)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(2)
  })

  it('redirectTo', async () => {
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('redirectTo')
    await new Promise((resolve) => {
      setTimeout(resolve, 1000)
    })
    page = await program.redirectTo(CURRENT_PAGE_PATH)
    await page.waitFor(1000)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(2)
  })

  it('switchTab', async () => {
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('switchTab')
    await new Promise((resolve) => {
      setTimeout(resolve, 1000)
    })
    page = await program.navigateTo(CURRENT_PAGE_PATH)
    await page.waitFor(1000)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(2)
  })

  it('reset lifecycle', async () => {
    const resetLifecycleNum = 1100
    await page.callMethod('setLifeCycleNum', resetLifecycleNum)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(resetLifecycleNum)
  })
})