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
@@ -899,7 +926,7 @@ test('Display loading state while waiting for data and then fetched profile nick
899
926
</TabItem>
900
927
</Tabs>
901
928
902
-
We query tab buttons and mock fetch function using `spyOn` and `mockImplementation`. We navigate to profile screen and check if loading state is rendered correctly. Then, to check if fetched data is displayed, we use `findByText` - we need to wait for the fetch to finish before checking it's result. To ensure that operation will succeed not only on the first focus, we navigate back to home, then to settings and check loading state and fetched data again.
929
+
We query tab buttons and mock fetch function using `spyOn` and `mockImplementation`. We navigate to profile screen and check if loading state is rendered correctly. Then, to check if fetched data is displayed, we use `findByText` - we need to wait for the fetch to finish before checking its result. To ensure that operation will succeed not only on the first focus, we navigate back to home, then to settings and check loading state and fetched data again.
903
930
904
931
To make test deterministic and isolate it from the real backend you can mock fetch function. You can use `spyOn` to override real implementation of fetch with `mockedFetch`.
905
932
@@ -920,7 +947,7 @@ async function mockedFetch() {
920
947
};
921
948
}
922
949
923
-
test('display loading state while waiting for data and then fetched profile nick on every profile screen focus', async () => {
950
+
test('on every profile screen focus, displays loading state while waiting for data and then shows fetched profile', async () => {
924
951
// ...
925
952
926
953
// Replace fetch implementation with mock
@@ -941,3 +968,4 @@ There are a couple of things to keep in mind when writing tests for components u
941
968
942
969
1. Avoid mocking React Navigation. Instead, use a real navigator in your tests.
943
970
2. Don't check for navigation actions. Instead, check for the result of the navigation such as the screen being rendered.
971
+
3. Remember to use fake timers when testing code that involves animations (e.g. transitions between screens with `StackNavigator`).
0 commit comments