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

describe('component-lifecycle', () => {
  let page
	let lifeCycleNum
  beforeAll(async () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
8
    page = await program.reLaunch(HOME_PATH)
9
    await page.waitFor(700)
DCloud-WZF's avatar
DCloud-WZF 已提交
10 11
    const initLifecycleNum = 0
    await page.callMethod('setLifeCycleNum', initLifecycleNum)
DCloud-WZF's avatar
DCloud-WZF 已提交
12 13 14 15
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(initLifecycleNum)

    page = await program.navigateTo(PAGE_PATH)
16
    await page.waitFor(700)
DCloud-WZF's avatar
DCloud-WZF 已提交
17
  })
DCloud-WZF's avatar
DCloud-WZF 已提交
18 19 20 21 22 23 24
  afterAll(async () => {
    const resetLifecycleNum = 1100
    await page.callMethod('setLifeCycleNum', resetLifecycleNum)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(resetLifecycleNum)
  })
	
DCloud-WZF's avatar
DCloud-WZF 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
  it('beforeCreate created beforeMount mounted', async () => {
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(4)
  })
  it('beforeUpdate updated', async () => {
		const component = await page.$('.component-lifecycle')
		await component.setData({
			title: 'component for lifecycle test new title'
		})
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(6)
  })
  it('beforeUnmount unmounted', async () => {
    page = await program.navigateBack()
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(4)
  })
})