How to mix Jest expect with Detox expect? Here is what I try to do. It seem expect
has overrided the 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?
This is done in two steps:
detox.init()
, pass a false initGlobals
parameter, e.g.: detox.init({ initGlobals: false })
. This will disable overriding global vars like expect
of Jest.const { device, expect } = require('detox');
or a similar ES6 import.Another alternative is to ignore the fact that Detox overwrote expect
, and re-import Jest's expect
under a different name.
const jestExpect = require('expect');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With