将玩笑期望与排毒期望混合

inv*_*sal 4 jestjs react-native detox

如何将 Jest expect 与 Detox expect 混合使用?这是我尝试做的。似乎expect已经盖过了笑话expect

await mockServer.mockAnyResponse({
    httpRequest: {
      method: 'POST', 
      path: '/api/register',
    },
    httpResponse: {
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        token: 'xxx',
      }),
    }
});

await element(by.id('name')).typeText('Robert');
await element(by.id('password')).typeText('123456');
await element(by.id('register')).tap();

// Check if endpoint has been called
let result = await mockServer.checkIfRegisterEndPointHasBeenCalled();
expect(result).toBe(true); // <-- how to do something like this?
Run Code Online (Sandbox Code Playgroud)

noo*_*rph 5

这分两步完成:

  1. 当您使用 时detox.init(),传递一个假initGlobals参数,例如:detox.init({ initGlobals: false })。这将禁用像expectJest这样的覆盖全局变量。
  2. 通过const { device, expect } = require('detox');或类似的 ES6 导入使用 detox 公共变量。

  • node 中仍然不支持 ES6 导入,你必须为此对你的测试进行 Babel,这大大增加了设置的复杂性。 (2认同)