New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug] Cannot run Jest Testing: cannot read properties of undefined (reading 'map') #15125
Comments
Hi @charlestbell, I think the problem is in the way in which you are trying to open the existing database. Please check the guide on that in the SQLite docs: After implementing the suggested |
I was not able to replicate your results. I installed expo-asset and expo-file system and created the metro.config.js file as per the documentation you listed. If there was more than that I was supposed to do, it was not aparent. I still get the same 'Cannot reac properties of undefined (reading 'map') error when I run
The code I have in the example is exact syntax to what's explained in this course: https://www.udemy.com/course/react-native-the-practical-guide/learn/lecture/15675384?start=165
Please share your code. Thanks, |
I got it. Used some syntax from a youtube video. https://www.youtube.com/watch?v=wAyizHBFQEs It appears that in the current version, you can't have a seperated init() statement like in Max's tutorial. Code before:
Code after
Note: I removed the init statement from App.js Edit: Code example |
@charlestbell Were you in fact able to get Expo SQLite running in your Jest tests? Can you share what the code looked like for doing so? I'm experimenting with using it and would like to have it in my Jest tests, and I'm getting the same error message you quoted in the original description. From the implementation code, it looks to me like it just can't run in Jest -- there's a native module for Android and one for iOS, and not one that would run in the Jest environment on Node. But I'd love to see a demonstration of how it can work after all. In the before/after in your last comment, it looks like the only difference was to remove the call to In the YouTube tutorial you link to, the test is here: |
Hi gnprice, I did get it working for a bit. And by working, I mean my tests would run. However, they were tests that didn't use expo-sqlite. Later, I tried to write tests that do use expo-sqlite, but that requireds the package to be mocked, and I couldn't make sense of the documentation there, so I moved on because it wasn't part of my minimum viable product. I'll post here when I get it. Sorry I can't be more helpful. |
Very helpful, thanks for the followup! So that matches my understanding of the current state of things. I actually went on yesterday to write up a mock, and I now have tests that do use expo-sqlite running in Jest. (If "mock" is even the right word -- it uses a real SQLite database, as it has to in order to faithfully test code that might be trying to run all kinds of SQL statements. Fortunately SQLite is super lightweight and can do that in memory, without even making a database file or anything.) I expect to have that ready to merge in our own codebase next week, and then I'll post something here in expo/expo and add a link from this thread. Not sure exactly the right way to integrate it into Expo so everyone can just have it work out of the box, but I'll ask. And if that turns out to be hard or gets stalled, my version should be pretty easy to copy-paste. |
Summary
Using Jest and Testing Library and Expo SQLite.
When I run Jest, I get an error that says
If I remove the init() call, the error dissapears, and the tests run.
I made a repo to demonstrate this, see that below.
Managed or bare workflow? If you have
ios/
orandroid/
directories in your project, the answer is bare!managed
What platform(s) does this occur on?
iOS
SDK Version (managed workflow only)
43
Environment
Expo CLI 4.12.12 environment info:
System:
OS: Windows 10 10.0.19042
Binaries:
Node: 16.9.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.17 - C:\Program Files\nodejs\yarn.CMD
npm: 7.21.1 - C:\Program Files\nodejs\npm.CMD
SDKs:
Android SDK:
API Levels: 28, 29, 30, 31
Build Tools: 28.0.3, 29.0.3, 32.0.0
System Images: android-28 | Google APIs Intel x86 Atom_64, android-30 | Google APIs Intel x86 Atom, android-30 | Google Play Intel x86 Atom
IDEs:
Android Studio: Version 4.2.0.0 AI-202.7660.26.42.7351085
npmPackages:
expo: ^43.0.0 => 43.0.2
react: 17.0.1 => 17.0.1
react-dom: 17.0.1 => 17.0.1
react-native: 0.64.2 => 0.64.2
react-native-web: 0.17.1 => 0.17.1
Expo Workflow: managed
Reproducible demo or steps to reproduce from a blank project
Link to demo repo
https://github.com/charlestbell/Expo-SQLite-Map-Bug
Steps:
yarn
)yarn test
)Test should fail to run
yarn test
)Test should run
The text was updated successfully, but these errors were encountered: