Mocking APIs in End to End Testing with Detox and React-Native

681 Views Asked by At

Has anyone been able to mock APIs in React-Native when doing end to end testing with Detox.

I tried using MirageJs. I am able to mock the APIs after creating a server with MirageJs and initializing it on App.js. The request is successfully mocked when running the app as normal "react-native run-ios"

However when running the e2e.js file, the API request is not being mocked. In the test file I included the following

let server
beforeEach(() => {
    server = makeServer()
})

afterEach(() => {
    server.shutdown()
})

And the server seems to be created. But the API is not mocked.

Happy to hear from anyone who has been able to mock APIs in detox test using MirageJS or a different approach

0

There are 0 best solutions below