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
Copy file name to clipboardExpand all lines: website/docs/Troubleshooting.md
+39-1Lines changed: 39 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,6 @@ import TOCInline from '@theme/TOCInline';
7
7
This guide describes common issues found by users when integrating React Native Test Library to their projects:
8
8
9
9
<TOCInlinetoc={toc} />
10
-
11
10
## Matching React Native, React & React Test Renderer versions
12
11
13
12
Check that you have matching versions of core dependencies:
@@ -33,6 +32,45 @@ We maintain an [example repository](https://github.com/callstack/react-native-te
33
32
34
33
In case something does not work in your setup you can refer to this repository for recommended configuration.
35
34
35
+
## Undefined component error
36
+
37
+
> Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
38
+
39
+
This frequently happens when you mock a complex module incorrectly, e.g.:
40
+
41
+
```ts
42
+
jest.mock('@react-navigation/native', () => {
43
+
return {
44
+
useNavigation: jest.fn(),
45
+
};
46
+
})
47
+
```
48
+
49
+
The above mock will mock `useNavigation` hook as intended, but at the same time all other exports from `@react-navigation/native` package are now `undefined`. If you want to use `NavigationContainer` component from the same package it will be `undefined` and result in the error above.
50
+
51
+
In order to mock only a part of given package you should re-export all other exports using `jest.requireActual` helper:
That way the mock will re-export all of the `@react-navigation/native` members and overwrite only the `useNavigation` hook.
63
+
64
+
Alternatively, you can use `jest.spyOn` to mock package exports selectively.
65
+
66
+
### Mocking React Native
67
+
68
+
In case of mocking `react-native` package you should not mock the whole package at once, as this approach has issues with `jest.requireActual` call. In this case it is recommended to mock particular library paths inside the package, e.g.:
0 commit comments