Default AsyncStorage values in a Detox test

Viewed 195

I'm wondering how to default AsyncStorage values in React Native for a Detox test.

I have a welcome modal which shows when the user firsts login. We control whether to show the modal by storing an AsyncStorage value. Since our tests launch different instances of the apps (with different settings), I'm looking for a way to default a value before a test begins.

I shortly investigated using a jest mock but not sure that's the right approach because I don't want to mock all of .getItem, I just want to mock it for this specific value that is stored.

1 Answers

I do it by opening the app with a dynamic link like this:

myapp://example/?action=setAsyncStorage&key=someKey&value=someValue

The app has a dynamiclink handler that recognizes this dynamic link and sets a value into AsyncStorage.

Related