You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been trying to add tests for my project using Realm, jest, and react-native-testing-library. For the most part, I have a set of working tests, but it's taken a lot of trial and error and research to get here. I would like to get some feedback on testing best practices with the Realm library by hearing about experiences of others.
Issue 1:
The tests seem to fail about 1/10 times when I run tests over and over. The failure looks like this: Accessing object of type Session which has been invalidated or deleted. I'm not exactly sure why this error happens (arbitrarily?).
Issue 2:
I have been reading a lot about how act should not be needed for fireEvent from react-native-testing-library since fireEvent is already wrapped with act. However, I've noticed that if I don't wrap my fireEvents that modify Realm state, then my tests are super flaky. Sometimes you run the test and don't get the act warning and other times you do. I assume this is a timing issue as sometimes the Realm state will be updated before the test ends and other times, the Realm will be updated after the test ends.
In addition to this, I notice the tests in this repo for RealmProvider are also wrapping fireEvent in act.
I'm not sure how this extra act wrapping gets rid of the act warning, but it does.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi there!
I have been trying to add tests for my project using Realm, jest, and react-native-testing-library. For the most part, I have a set of working tests, but it's taken a lot of trial and error and research to get here. I would like to get some feedback on testing best practices with the Realm library by hearing about experiences of others.
Issue 1:
The tests seem to fail about 1/10 times when I run tests over and over. The failure looks like this:
Accessing object of type Session which has been invalidated or deleted
. I'm not exactly sure why this error happens (arbitrarily?).Issue 2:
I have been reading a lot about how
act
should not be needed forfireEvent
from react-native-testing-library sincefireEvent
is already wrapped withact
. However, I've noticed that if I don't wrap myfireEvents
that modify Realm state, then my tests are super flaky. Sometimes you run the test and don't get the act warning and other times you do. I assume this is a timing issue as sometimes the Realm state will be updated before the test ends and other times, the Realm will be updated after the test ends.In addition to this, I notice the tests in this repo for RealmProvider are also wrapping
fireEvent
inact
.I'm not sure how this extra
act
wrapping gets rid of theact
warning, but it does.Thank you in advance for any insight!
Beta Was this translation helpful? Give feedback.
All reactions