Closed
Description
Describe the bug
After updating to the latest version, I got this error in my tests (in all of them which use react testing library):
Trying to detect host component names triggered the following error:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Check the render method of `ForwardRef(Switch)`.
There seems to be an issue with your configuration that prevents React Native Testing Library from working correctly.
Please check if you are using compatible versions of React Native and React Native Testing Library.
The thing is I'm not using the Switch
component anywhere in my app nor the tests, I've been using this patch to workaround it:
diff --git a/node_modules/@testing-library/react-native/build/helpers/host-component-names.js b/node_modules/@testing-library/react-native/build/helpers/host-component-names.js
index 48923cd..d335c96 100644
--- a/node_modules/@testing-library/react-native/build/helpers/host-component-names.js
+++ b/node_modules/@testing-library/react-native/build/helpers/host-component-names.js
@@ -47,9 +47,9 @@ function detectHostComponentNames() {
testID: "textInput"
}), /*#__PURE__*/React.createElement(_reactNative.Image, {
testID: "image"
- }), /*#__PURE__*/React.createElement(_reactNative.Switch, {
+ }), /*#__PURE__*//*React.createElement(_reactNative.Switch, {
testID: "switch"
- }), /*#__PURE__*/React.createElement(_reactNative.ScrollView, {
+ }),*/ /*#__PURE__*/React.createElement(_reactNative.ScrollView, {
testID: "scrollView"
}), /*#__PURE__*/React.createElement(_reactNative.Modal, {
testID: "modal"
@@ -58,7 +58,7 @@ function detectHostComponentNames() {
text: getByTestId(renderer.root, 'text').type,
textInput: getByTestId(renderer.root, 'textInput').type,
image: getByTestId(renderer.root, 'image').type,
- switch: getByTestId(renderer.root, 'switch').type,
+ switch: /*getByTestId(renderer.root, 'switch').type,*/"RCTSwitch",
scrollView: getByTestId(renderer.root, 'scrollView').type,
modal: getByTestId(renderer.root, 'modal').type
};
Expected behavior
This error should not happen
Steps to Reproduce
N/A
Screenshots
N/A
Versions
@testing-library/react-native: 12.8.1 => 12.8.1
react: 18.3.1 => 18.3.1
react-native: 0.76.1 => 0.76.1
Metadata
Metadata
Assignees
Labels
No labels