Skip to content
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

Error with Switch component after upgrading #1708

Open
andresmartinezstay opened this issue Nov 20, 2024 · 0 comments
Open

Error with Switch component after upgrading #1708

andresmartinezstay opened this issue Nov 20, 2024 · 0 comments

Comments

@andresmartinezstay
Copy link

andresmartinezstay commented Nov 20, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant