收藏
回答

自动化测试 mockWxMethod(request) 报错 _from、_promise 未定义

const path = require('path');
const automator = require('miniprogram-automator');
let e2eRc = require(path.resolve(process.cwd(), '.e2erc.js'));
let timer = null;
jest.setTimeout(30000000);
describe('minitest-2', () => {
  let miniProgram;
  beforeAll(async () => {
    miniProgram = await automator.launch({
      projectPath: e2eRc.projectPath,
    });
  }, 30000000);
  afterAll(async () => {
    clearInterval(timer);
    await miniProgram.disconnect();
  });
  it('minitest-2', async () => {

   // request 不能 mock 了
    await miniProgram.mockWxMethod(
      'request',
      function(obj, platform) {
        console.log('typeof Promise ----->', typeof Promise); // 模拟器无输出
        return new Promise((resolve, reject) => {
           this.origin({...obj, success (res) { resolve(res)} });
        })
      }
    );

    let page;
    page = await miniProgram.currentPage();
    await page.waitFor(10000);
  });
});



回答关注问题邀请回答
收藏

2 个回答

  • RedHood
    RedHood
    2022-09-21

    工具上试下关闭启用独立域调试选项看能不能行

    2022-09-21
    有用
    回复 2
    • Bingo
      Bingo
      2022-09-21
      刚试了一下,关闭独立域调试后仍然会有报错
      2022-09-21
      回复
    • Bingo
      Bingo
      2022-09-21
      感觉是mock函数里面的代码被 polyfill 了,但有些全局的polyfill访问不到
      2022-09-21
      回复
  • Bingo
    Bingo
    2022-09-20

    刚刚试了一下真机也会有同样的报错

    2022-09-20
    有用
    回复
登录 后发表内容