DevExpress / testcafe-react-selectors

TestCafe selector extensions for React apps.
https://testcafe.io
MIT License
205 stars 43 forks source link

Fix TypeError while searching for children inside a React.Suspense #193

Closed omacranger closed 1 year ago

omacranger commented 1 year ago

Hello!

While working on an upgrade to React 18 we were running into some issues with the results of components / bundles loaded via Suspense. After spending a decent amount of time I tracked it down to this repo and a property being accessed that may not exist yet. I also bumped the testcafe version in the package.json to fix build errors with TypeScript, and just have the latest version tested against.

The Bug:

When attempting to find a child of a Suspense, the element for the requested selector inside a ReactSelector may not exist yet, which throws the following error:

 1) An error occurred in Selector code:

      TypeError: Cannot read properties of undefined (reading 'type')

The Fix:

I tracked it down to the getName function, and have adding a [previously] failing test case, and a fix in the form of an optional chain when accessing that property.

currentElement.type => currentElement?.type

Let me know if I missed something or if I can help provide a better example. Thanks!

github-actions[bot] commented 1 year ago

Thank you for your contribution to TestCafe. We will review this PR.

kirovboris commented 1 year ago

Published testcafe-react-selectors@5.0.3