锁定微信原生页跳转失败提示
H5 HostBridge 微信小程序跳转失败不再透出原生 errMsg HostBridge 测试覆盖微信跳转失败稳定提示 native shell 总门禁反查微信跳转失败边界
This commit is contained in:
@@ -767,6 +767,40 @@ describe('hostBridge', () => {
|
||||
await expect(requestWechatMiniProgramPhoneLogin()).resolves.toBe(true);
|
||||
});
|
||||
|
||||
test('hides wechat mini program navigation native failure details', async () => {
|
||||
const consoleError = vi
|
||||
.spyOn(console, 'error')
|
||||
.mockImplementation(() => undefined);
|
||||
const navigationError = {
|
||||
errMsg: 'navigateTo:fail private native detail',
|
||||
};
|
||||
const navigateTo = vi.fn((options) => {
|
||||
options.fail?.(navigationError);
|
||||
});
|
||||
window.history.replaceState(
|
||||
null,
|
||||
'',
|
||||
'/?clientRuntime=wechat_mini_program',
|
||||
);
|
||||
window.wx = {
|
||||
miniProgram: {
|
||||
navigateTo,
|
||||
},
|
||||
};
|
||||
|
||||
await expect(requestHostLogin()).rejects.toThrow(
|
||||
'请在微信小程序内完成登录',
|
||||
);
|
||||
await expect(requestHostLogin()).rejects.not.toThrow(
|
||||
'private native detail',
|
||||
);
|
||||
expect(consoleError).toHaveBeenCalledWith(
|
||||
'[host-bridge] wechat mini program navigation failed',
|
||||
navigationError,
|
||||
);
|
||||
consoleError.mockRestore();
|
||||
});
|
||||
|
||||
test('通过微信小程序原生页请求支付', async () => {
|
||||
const navigateTo = vi.fn((options) => {
|
||||
options.success?.();
|
||||
|
||||
@@ -496,7 +496,11 @@ export async function navigateWechatMiniProgramPage(
|
||||
resolve();
|
||||
},
|
||||
fail(error) {
|
||||
reject(new Error(error?.errMsg || errorMessage));
|
||||
console.error(
|
||||
'[host-bridge] wechat mini program navigation failed',
|
||||
error,
|
||||
);
|
||||
reject(new Error(errorMessage));
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user