page.test.js 1.9 KB
Newer Older
H
hdx 已提交
1
const PAGE_PATH = '/pages/lifecycle/page/page'
DCloud-WZF's avatar
DCloud-WZF 已提交
2 3 4 5 6 7
const HOME_PATH = '/pages/index'

describe('page-lifecycle', () => {
  let page
	let lifeCycleNum
  beforeAll(async () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
8 9 10 11 12 13 14 15 16 17
    page = await program.reLaunch(HOME_PATH)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(1100)

		const initLifecycleNum = 0
		await page.callMethod('setLifeCycleNum', initLifecycleNum)
		lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(initLifecycleNum)
    
		page = await program.reLaunch(PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
18 19 20 21
    await page.waitFor(1000)
  })
  it('onLoad onShow onReady', async () => {
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
DCloud-WZF's avatar
DCloud-WZF 已提交
22
    expect(lifeCycleNum).toBe(120)
DCloud-WZF's avatar
DCloud-WZF 已提交
23 24 25 26
  })
  it('onHide', async () => {
    page = await program.navigateTo(HOME_PATH)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
DCloud-WZF's avatar
DCloud-WZF 已提交
27
    expect(lifeCycleNum).toBe(110)
DCloud-WZF's avatar
DCloud-WZF 已提交
28 29
		page = await program.navigateBack()
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
DCloud-WZF's avatar
DCloud-WZF 已提交
30
    expect(lifeCycleNum).toBe(120)
DCloud-WZF's avatar
DCloud-WZF 已提交
31 32 33 34
  })
  it('onUnload', async () => {
    page = await program.redirectTo(HOME_PATH)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
DCloud-WZF's avatar
DCloud-WZF 已提交
35
    expect(lifeCycleNum).toBe(20)
DCloud-WZF's avatar
DCloud-WZF 已提交
36 37 38 39
  })
  it('onBackPress', async () => {
    page = await program.navigateTo(PAGE_PATH)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
DCloud-WZF's avatar
DCloud-WZF 已提交
40
    expect(lifeCycleNum).toBe(140)
DCloud-WZF's avatar
DCloud-WZF 已提交
41 42
    page = await program.navigateBack()
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
DCloud-WZF's avatar
DCloud-WZF 已提交
43
    expect(lifeCycleNum).toBe(30)
DCloud-WZF's avatar
DCloud-WZF 已提交
44 45 46 47
  })
	it('onLastPageBackPress', async () => {
	  page = await program.navigateBack()
	  lifeCycleNum = await page.callMethod('getLifeCycleNum')
DCloud-WZF's avatar
DCloud-WZF 已提交
48 49 50 51 52 53
    expect(lifeCycleNum).toBe(-970)
    
		const resetLifecycleNum = 1100
		await page.callMethod('setLifeCycleNum', resetLifecycleNum)
		lifeCycleNum = await page.callMethod('getLifeCycleNum')
		expect(lifeCycleNum).toBe(resetLifecycleNum)
DCloud-WZF's avatar
DCloud-WZF 已提交
54
	})
DCloud-WZF's avatar
DCloud-WZF 已提交
55
})