antoniopresto / react-native-local-mongodb

react-native local mongodb storage.
MIT License
303 stars 66 forks source link

Testing not working #77

Open hscrocha opened 2 years ago

hscrocha commented 2 years ago

I cant seem to get testing to work. I installed the dev dependencies, and I am trying to create a in-memory DB for my test.

First by using the example "const db = new Datastore()" does not work, and the error says options.storage is not defined (even though the readme has no info on whether storage is optional/mandatory). I also tried "const db = new Datastore({inMemoryOnly:true});" same issue.

If I set storage using the AsyncStorage, then the problem changes as AsyncStorage cannot be used in Jest. All docs on testing AsyncStorage tell to mock it. The general mock codes I can find do not seem to work with the react-native-local-mongodb.

How can you set up the test environment to use the Datastore in Jest?