testing-library / native-testing-library

🐳 Simple and complete React Native testing utilities that encourage good testing practices.
https://native-testing-library.com
MIT License
516 stars 44 forks source link

Change validTargets to list of components, not component names #115

Closed gabalafou closed 4 years ago

gabalafou commented 4 years ago

What:

Before this change, NativeTestEvent.validTargets was an array of component names. Now it is an array of actual React Native components.

In addition, this diff fixes a bug in event tests where a describe() instead of a test() was being used, so the tests for every supported (component, event) pair were not being run (or were not being reported by the test runner).

Why:

I ran into a possible bug, when writing tests within an Expo project and using the "jest-expo" preset. I tried to fireEvent on a Switch element, but the handler for the event was never called. Digging in, I realized that my Switch's element.type was not the string "Switch"; it was the React Native Switch component class, which made me think that the assumption that element.type should be a string in validTargets is wrong.

Checklist:

thymikee commented 4 years ago

FYI, this repository is no longer responsible for this package. See the migration guide to v7.0.

If this is still applicable to v7, please send the PR there :)