-
Notifications
You must be signed in to change notification settings - Fork 602
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
Setup and Teardown test database in Jest results in database action errors #459
Comments
I don’t know much about Enzyme, so I don’t know how to help with the withObservables problem (although I suspect it has something to do with the fact that it’s asynchronous, and so you might only get a full render on the second render. But the issue with actions is very strange. I suggest you follow the code in |
Thanks for the quick reply! I will definitely look into the One detail I forgot to mention is that this |
no idea — the only thing that comes to mind is that you downloaded a newer version of watermelon which has some sort of a regression, but I haven’t seen iissues of that kind on our project. |
Alright, so after doing some digging I figured that it has to do with the asynchronous nature of WatermelonDB. I set up the database and adapter outside of async functions, not so sure if that is exactly why it ended up showing me errors. Would need to do some more research into that. What I found and suspect is that the action error is functioning more as a catchall error. When the adapter/database hasn't been initialised yet and you start running actions on top if it, it throws the action error. It seems more like the action can't be executed yet since the database is not ready to accept any traffic at that state. Correct me if I'm wrong on this hypothesis! This would also explain why I started getting similar errors in the app itself, maybe after hot reloads the database gets in this funny state where it can't accept any actions causing the overall action wrapper error to be thrown. |
Hmm, it's possible, but that would be a bug. While the database sets up asynchronously, it should be able to accept actions immediately (they should just queue and execute in order when ready) |
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
We're looking for some guidance on testing our application with WatermelonDB. Our understanding is that we'll need to have a test database with setup, seeded data and tear down.
After a couple days of experimentation, here are a couple of related issues we are stuck on. Would appreciate any thoughts you have on them. (The test setup is
jest
withenzyme
):... can only be called from inside of an Action. See docs for more details.
An example of the beforeEach code with the database setup:
Results in the error
Collection.create() can only be called from inside of an Action. See docs for more details.
on runtime. A similar thing happens when I try to clean up the database after the code has runawait database.action(async () => await database.unsafeResetDatabase())
.In general, we've noticed this behaviour pop-up on occasion inside the app, without a discernible pattern. Have you seen this kind of thing before?
withObservables
(as a HOC) using Enzyme's.dive()
results in aTypeError: ShallowWrapper::dive() can only be called on components
We have a
<Tab>
component wrapped inwithObservables
HOC. For testing in enzyme, we need to call.dive()
on the HOC to go down one layer and render the children. Here we get the above error. We've tested this with other HOCs without an issue. (Appreciate this has to do with Enzyme too.)useDatabase
context hook is causing Enzyme problems.This is more of an issue with Enzyme rather than WatermelonDB, but we would like to get some insights on how we could work our way around this. We have found this comment seemingly working around the useContext problem. We've tried a similar approach, but that brought us to another error where it seems we can't mock the return value of useDatabase. (Tried this with Sinon.stub, Jest.spyOn and Jest.fn)
If any testing experiences / insights can be shared when it comes to WatermelonDB that'd be dearly appreciated!
The text was updated successfully, but these errors were encountered: