如何混合Jest expect和Detox expect?这就是我想要做的。看起来expect已经覆盖了jest 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?发布于 2018-07-13 13:35:16
这分两步完成:
detox.init()时,请传递一个假的initGlobals参数,例如:detox.init({ initGlobals: false })。这将禁用覆盖全局变量,如expect of Jest。const { device, expect } = require('detox');或类似的ES6导入使用排毒公共变量。发布于 2018-10-29 22:53:31
另一种选择是忽略Detox覆盖expect的事实,并以不同的名称重新导入Jest的expect。
const jestExpect = require('expect');
发布于 2019-10-07 17:07:58
我不确定这对于更有经验的“测试人员”是否显而易见,但其他两个答案只有部分正确,并且遗漏了一些我遇到的问题:当您尝试全局访问或require expect时,您会得到undefined,您必须在测试中执行此操作。
因此,您必须执行以下操作:
在init.js文件中:
before(async () => {
await detox.init(config, {initGlobals: false});
});在您的测试文件中-实际的it (带有const)或before (带有let jestExpect在describe中):
jestExpect = require('expect');https://stackoverflow.com/questions/51317247
复制相似问题