Search code examples
react-nativeasyncstoragedetox

Detox with @react-native-community/async-storage issue?


I am trying to set up my project to run detox e2e tests that were generated by someone else. I am getting an issue that Async-Storage is null. The project runs properly if I am just doing run-android or run-ios, but when I try to run the detox tests, I get the error. Is there a way that I am supposed to mock this function like with Jest? I tried google the error and Async-Storage with detox, but I only get people having issues with the Android setup, with which I am not having issues. My issues only arise when running detox tests. Any help is greatly appreciated!


Solution

  • In case anyone has this same issue and runs across this, make sure you add this to your setup file for detox/jest:

    import mockAsyncStorage from "@react-native-community/async-storage/jest/async-storage-mock";

    jest.mock("@react-native-community/async-storage", () => mockAsyncStorage);