`expo-secure-store`'s SecureStore.setItemAsync and getItemAsync not working with JEST

@amanhimself Can you please check this

@wodin Can you please check this

Hi @supriya_kalghatgi

I have not used jest before. Also, I am just an Expo user like you. I don’t work for them :slight_smile:

But if you’re mocking expo-secure-store, then is it really SecureStore.setItemAsync() that’s not working?

@wodin Yes, SecureStore.setItemAsync() does not work in case of jest
Whereas @react-native-async-storage/async-storage’s AsyncStorage.setItem() works
Not sure whats wrong here either in my mock or with SecureStore

@brents Can you please check this

So you’re saying that when you mock expo-secure-store then your mock doesn’t work, but when you mock @react-native-async-storage/async-storage then your mock works?

Then I suppose one possibility would be to switch to @react-native-async-storage/async-storage.

If you want to stay with expo-secure-store and if you do not get a better answer here, try posting your question to Stack Overflow, but provide more details. What do you mean by “not working”? Do you get an error message? What is the error message? etc.

@wodin No error message
Not working - I mean I dont get the token with SecureStore
Into my project, I have SecureStore for tokens and user details stuff
Whereas for other non confidential stuff, I use AsyncStorage.
So I cannot change this approach just because I dont get jest working with this
You asked to provide more details, do you want me to share package.json and jest config?

No help

That’s not the same question. That person was asking if they could use expo-secure-store directly in jest without mocking.

I mean the suggestion about mock given in answer did not help

I have now raised this on SO

OK, good luck. But you might want to edit the question to replace the image with the actual code. That’s easier for people to work with if they’re trying to test and reproduce the problem.

1 Like