All files / mp navigatePageBack.ts

100% Statements 3/3
100% Branches 1/1
100% Functions 3/3
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20                1x   1x 1x                
import { ensureInMiniProgram } from './ensureInMiniProgram'
 
/**
 * 关闭当前页面,返回上一页面或多级页面。
 *
 * @param delta 返回的页面数,如果 delta 大于现有页面数,则返回到首页
 */
export function navigatePageBack(delta = 1): Promise<any> {
  return ensureInMiniProgram(
    mp =>
      new Promise((resolve, reject) => {
        mp.navigateBack({
          delta: delta,
          success: resolve,
          fail: reject,
        })
      }),
  )
}