提交 23f789b1 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

test(API): navigateBack delta

上级 cf481cf3
jest.setTimeout(40000)
const CURRENT_PAGE_PATH = '/pages/API/navigator/navigator'
const HOME_PAGE_PATH = '/pages/tabBar/component'
describe('navigator', () => {
let page
let lifeCycleNum
afterAll(async () => {
const resetLifecycleNum = 1100
await page.callMethod('setLifeCycleNum', resetLifecycleNum)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(resetLifecycleNum)
})
it('reLaunch', async () => {
page = await program.navigateTo(CURRENT_PAGE_PATH)
await page.waitFor(1000)
await page.waitFor(500)
await page.callMethod('setLifeCycleNum', 0)
await page.callMethod('reLaunch')
await new Promise((resolve) => {
setTimeout(resolve, 1000)
})
await page.waitFor(500)
page = await program.navigateTo(CURRENT_PAGE_PATH)
await page.waitFor(1000)
await page.waitFor(500)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(2)
})
......@@ -22,19 +27,17 @@ describe('navigator', () => {
it('navigateTo', async () => {
await page.callMethod('setLifeCycleNum', 0)
await page.callMethod('navigateTo')
await new Promise((resolve) => {
setTimeout(resolve, 1000)
})
await page.waitFor(500)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(2)
page = await program.navigateBack()
await page.waitFor(1000)
await page.waitFor(500)
})
it('navigateTo error page', async () => {
await page.callMethod('setLifeCycleNum', 0)
await page.callMethod('navigateToErrorPage')
await page.waitFor(1000)
await page.waitFor(500)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(2)
})
......@@ -42,53 +45,70 @@ describe('navigator', () => {
it('navigateTo debounce', async () => {
await page.callMethod('setLifeCycleNum', 0)
await page.callMethod('navigateToDebounce')
await new Promise((resolve) => {
setTimeout(resolve, 1000)
})
await page.waitFor(500)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(4)
page = await program.navigateBack()
await page.waitFor(1000)
await page.waitFor(500)
})
it('navigateTo relative path', async () => {
await page.callMethod('setLifeCycleNum', 0)
await page.callMethod('navigateToRelativePath1')
page = await program.navigateBack()
await page.waitFor(1000)
await page.waitFor(500)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(2)
await page.waitFor(1000)
await page.waitFor(500)
})
it('navigateTo relative path ./', async () => {
await page.callMethod('setLifeCycleNum', 0)
await page.callMethod('navigateToRelativePath2')
page = await program.navigateBack()
await page.waitFor(1000)
await page.waitFor(500)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(2)
await page.waitFor(1000)
await page.waitFor(500)
})
it('navigateTo relative path ../', async () => {
await page.callMethod('setLifeCycleNum', 0)
await page.callMethod('navigateToRelativePath3')
page = await program.navigateBack()
await page.waitFor(1000)
await page.waitFor(500)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(2)
await page.waitFor(1000)
await page.waitFor(500)
})
it('navigateBack', async () => {
await page.callMethod('setLifeCycleNum', 0)
await page.callMethod('navigateBack')
await new Promise((resolve) => {
setTimeout(resolve, 1000)
})
await page.waitFor(500)
page = await program.navigateTo(CURRENT_PAGE_PATH)
await page.waitFor(500)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(2)
})
it('navigateBackWithDelta1', async () => {
await page.callMethod('setLifeCycleNum', 0)
await page.callMethod('navigateBackWithDelta1')
await page.waitFor(1000)
page = await program.currentPage()
expect(`/${page.path}`).toBe(CURRENT_PAGE_PATH)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(2)
})
it('navigateBackWithDelta100', async () => {
page = await program.reLaunch(CURRENT_PAGE_PATH)
await page.callMethod('setLifeCycleNum', 0)
await page.callMethod('navigateBackWithDelta100')
await page.waitFor(1000)
page = await program.currentPage()
expect(`/${page.path}`).toBe(CURRENT_PAGE_PATH)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(2)
})
......@@ -96,11 +116,9 @@ describe('navigator', () => {
it('redirectTo', async () => {
await page.callMethod('setLifeCycleNum', 0)
await page.callMethod('redirectTo')
await new Promise((resolve) => {
setTimeout(resolve, 1000)
})
await page.waitFor(500)
page = await program.redirectTo(CURRENT_PAGE_PATH)
await page.waitFor(1000)
await page.waitFor(500)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(2)
})
......@@ -108,19 +126,10 @@ describe('navigator', () => {
it('switchTab', async () => {
await page.callMethod('setLifeCycleNum', 0)
await page.callMethod('switchTab')
await new Promise((resolve) => {
setTimeout(resolve, 1000)
})
await page.waitFor(500)
page = await program.navigateTo(CURRENT_PAGE_PATH)
await page.waitFor(1000)
await page.waitFor(500)
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)
})
})
......@@ -240,6 +240,56 @@ export default {
},
})
},
navigateBackWithDelta1() {
uni.navigateTo({
url: '/pages/API/navigator/new-page/new-page-1',
success() {
uni.navigateBack({
delta: 1,
success(result) {
console.log('navigateBack success', result.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
fail(error) {
console.log('navigateBack fail', error.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 1)
},
complete(result) {
console.log('navigateBack complete', result.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
})
},
})
},
navigateBackWithDelta100() {
uni.navigateTo({
url: '/pages/API/navigator/new-page/new-page-1',
success() {
uni.navigateBack({
delta: 100,
success(result) {
console.log('navigateBack success', result.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
fail(error) {
console.log('navigateBack fail', error.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 1)
},
complete(result) {
console.log('navigateBack complete', result.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
})
},
})
},
redirectTo() {
uni.redirectTo({
url: '/pages/API/navigator/new-page/new-page-1?data=Hello',
......
......@@ -15,7 +15,6 @@ export default {
}
},
onLoad(options: OnLoadOptions) {
console.log('new-page2 onLoad', options)
if (options.has('data')) {
this.data = options.get('data')!
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册