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

An error was reported running the example #1422

Closed
dingsq820 opened this issue Jun 27, 2023 · 8 comments
Closed

An error was reported running the example #1422

dingsq820 opened this issue Jun 27, 2023 · 8 comments
Labels
question Further information is requested

Comments

@dingsq820
Copy link

dingsq820 commented Jun 27, 2023

The run example reports the following error:
` PASS tests/questionsBoard.test.tsx

console.error
  Warning: dispatchCommand was called with a ref that isn't a native component. Use React.forwardRef to get access to the underlying native component
      at Switch (/Users/linkage/Desktop/dingsq/开发/dw-app/node_modules/react-native/Libraries/Components/Switch/Switch.js:141:5)
      at View
      at Component (/Users/linkage/Desktop/dingsq/开发/dw-app/node_modules/react-native/jest/mockComponent.js:28:18)

  38 |   const mockFn = jest.fn();
  39 |
> 40 |   const { getAllByLabelText, getByText } = render(
     |                                                  ^
  41 |     <QuestionsBoard questions={allQuestions} onSubmit={mockFn} />
  42 |   );
  43 |

  at printWarning (node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:84:30)
  at error (node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:60:5)
  at dispatchCommand (node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:22918:7)
  at Object.setNativeValue (node_modules/react-native/Libraries/Utilities/codegenNativeCommands.js:22:22)
  at node_modules/react-native/Libraries/Components/Switch/Switch.js:179:31
  at commitHookEffectListMount (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11692:26)
  at commitLifeCycles (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11753:11)
  at commitLayoutEffects (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:14443:7)
  at HTMLUnknownElement.callCallback (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11391:14)
  at innerInvokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:316:27)
  at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:267:3)
  at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:214:9)
  at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:87:17)
  at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:144:23)
  at Object.invokeGuardedCallbackDev (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11440:16)
  at invokeGuardedCallback (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11499:31)
  at commitRootImpl (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:14172:9)
  at unstable_runWithPriority (node_modules/react-test-renderer/node_modules/scheduler/cjs/scheduler.development.js:468:12)
  at runWithPriority (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:2486:10)
  at commitRoot (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:14011:3)
  at performSyncWorkOnRoot (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:13440:3)
  at node_modules/react-test-renderer/cjs/react-test-renderer.development.js:2537:26
  at unstable_runWithPriority (node_modules/react-test-renderer/node_modules/scheduler/cjs/scheduler.development.js:468:12)
  at runWithPriority (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:2486:10)
  at flushSyncCallbackQueueImpl (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:2532:9)
  at flushSyncCallbackQueue (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:2519:3)
  at batchedUpdates (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:13459:7)
  at Object.act (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:15280:14)
  at renderWithAct (node_modules/@testing-library/react-native/src/render-act.ts:13:16)
  at detectHostComponentNames (node_modules/@testing-library/react-native/src/helpers/host-component-names.tsx:32:35)
  at configureHostComponentNamesIfNeeded (node_modules/@testing-library/react-native/src/helpers/host-component-names.tsx:26:30)
  at render (node_modules/@testing-library/react-native/src/render.tsx:36:38)
  at Object.<anonymous> (__tests__/questionsBoard.test.tsx:40:50)`
@dingsq820 dingsq820 added the question Further information is requested label Jun 27, 2023
@pierrezimmermannbam
Copy link
Collaborator

Hello @dingsq820, thanks for submitting the issue! When running this test in the react-native-testing-library repo I don't get this error, could you please detail the steps to reproduce it?

@mdjastrzebski
Copy link
Member

I confirm the tests are working fine for me. Closing as non-reproducible.

@mdjastrzebski mdjastrzebski closed this as not planned Won't fix, can't repro, duplicate, stale Jul 21, 2023
@kyleshevlin
Copy link

I have pinned down the version that started this issue as 12.1.2. Works fine in 12.1.1, I believe something may have happened in this commit: 72e3133

@pierrezimmermannbam
Copy link
Collaborator

Hello @kyleshevlin , where are you running the example from? This is not an issue with RNTL I think. It seems more related to the way the Switch component is mocked in React Native. It must have appeared because Switch is now rendered when we get the host component names because no switch is used in the QuestionBoard component. So imo this is a duplicate of #329

If we don't have this error in the RNTL repo maybe it's probably because it has been fixed and you're using older versions of RN? What version of RN are you using to reproduce the error?

@kyleshevlin
Copy link

Correct, we are stuck on react-native: 0.66.5. We are also using react-native-web (which may or may not apply). I was upgrading/downgrading @testing-library/react-native until I found the version that triggered the issue.

Since it's an older version of RN, I might not worry too much about it, I just wanted to add that detail in case it helps others.

@pierrezimmermannbam
Copy link
Collaborator

Have you tried solutions proposed in the other issue? This comment in the other issue gives a solution to fix that issue. It's what I used on previous rn versions

@mdjastrzebski
Copy link
Member

@kyleshevlin not sure how relevant is it for your case but you mentioned that you use React Native Web, which unfortunately we do not support. We recommend using regular React Testing Library for testing React Native Web for two reasons:

  1. It will give you much better testing environment due to using Jest DOM simulating browser environment.
  2. Our RN runtime simulation code is developed based only on iOS/Android env, and we simply do not have enough resources to target RN Web at this stage.

@mdjastrzebski
Copy link
Member

Closing as stale.

@mdjastrzebski mdjastrzebski closed this as not planned Won't fix, can't repro, duplicate, stale Sep 13, 2023
zatteo added a commit to cozy/cozy-flagship-app that referenced this issue Nov 22, 2023
There are useless warnings coming from the update of @testing-library/react-native linked to the Switch component and dispatchCommand. They are removed in React Native 0.72. This is a temporary mock to keep our tests clean.

callstack/react-native-testing-library#1422
zatteo added a commit to cozy/cozy-flagship-app that referenced this issue Dec 5, 2023
There are useless warnings coming from the update of @testing-library/react-native linked to the Switch component and dispatchCommand. They are removed in React Native 0.72. This is a temporary mock to keep our tests clean.

callstack/react-native-testing-library#1422
zatteo added a commit to cozy/cozy-flagship-app that referenced this issue Dec 5, 2023
There are useless warnings coming from the update of @testing-library/react-native linked to the Switch component and dispatchCommand. They are removed in React Native 0.72. This is a temporary mock to keep our tests clean.

callstack/react-native-testing-library#1422
zatteo added a commit to cozy/cozy-flagship-app that referenced this issue Dec 5, 2023
There are useless warnings coming from the update of @testing-library/react-native linked to the Switch component and dispatchCommand. They are removed in React Native 0.72. This is a temporary mock to keep our tests clean.

callstack/react-native-testing-library#1422
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants