Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Express more tests via public API #11299
This is a great contribution opportunity.
This means that they can only import npm entry points like
To help with this:
Step 3 requires some thinking. You can use previous examples where we rewrote tests with public API for inspiration. For example:
Generally, you need to think about how the behavior you’re testing actually reproduces in a React app, and then test for that. In rare cases it may involve exposing some API as public which we’ll need to discuss separately, so don’t hesitate to start a discussion! If you can’t figure out how to rewrite some particular test with a public API, comment here and we can brainstorm.
Here is the full list of tests that need to change. Some of them may be simple one-liner changes, some may involve a bit of a rewrite, some may require rewriting from scratch. Some may even be impossible, but research leading to that conclusion is still very valuable and we’d love to know that.
Try them and let us know:
Update: all tests are taken now. Subscribe to this issue! They might free up in the future if somebody doesn’t have the time to finish the work. We’ll comment if some test becomes available to try again.
First-time contributor? Refer to our contribution instructions.
Not clear how to fix a specific test? Comment with what you tried, and we can brainstorm.
If you gave up on some test, please post your findings in a comment so we can decide what to do next. It’s fine if you just didn’t find the time or couldn’t figure it out—we can try to help, and maybe somebody else can pick it up later.
* ValidateDOMNesting tests(#11299) * Rewrite tests using only public API. * Modified the tests to prevent duplication of code. * Code review changes implemented. * Removed the .internal from the test file name as its now written using public APIs. * Remove mutation * Remove unnecessary argument Now that we pass warnings, we don't need to pass a boolean. * Move things around a bit, and add component stack assertions
…facebook#11309) * Rewrite tests depending on internal API * Remove focus being called when there was no blur event function before * Remove triggering function and just let ReactTestUtils take care * Use native events * Remove duplicate * Simulate native event when changing value on reentrant * Change wasn't being called * Use Simulate only * Use React event handlers on test * Move commentary * Lint commit * Use native event * Comment native event dispatching * Prettier * add setUntrackedValue * Prettier-all * Use dispatchEvent instead of ReactTestUtils Simulates; * Prettier * Fix lint * Remove useless arg * Wrap event dispatcher into function * Remove deprecated Event * Remove unused change event dispatcher * Fix merge * Prettier * Add missing focus/blur calls They are necessary to cover for the fix in facebook#8240.
…11299) (facebook#11367) * Update SyntheticWheelEvent tests to use public API * Replace: ReactTestUtils.SimulateNative to native Events() * Update: Replaced WheelEvent() interface to document.createEvent * Fix: Lint SyntheticWheelEvent file * Update: Custom WheelEvent function to a generic MouseEvent function * Update: Prettier SyntheticWheelEvent-test.js * Verify the `button` property is set on synthetic event * Use MouseEvent constructor over custom helper * Rewrite to test React rather than jsdom * Force the .srcElement code path to execute * Style tweaks and slight code reorganization
…acebook#11383) * Rewrite ReactDOMComponentTree-test to test behavior using Public API - Part of facebook#11299 - I've tried to identify cases where code within ReactDOMComponentTree is exercised and have updated accordingly but I'm not entirely sure whether I'm on the right track. I thought I'd PR to get feedback from the community. Looking forward to comments. * Prettier and lint changes * Remove testing of internals and add test cases for testing behavior exhibited after use of getInstanceFromNode * [RFC] Update testing approach to verify exhibited behavior dependent upon methods in ReactDOMComponentTree * Remove tests from event handlers and use sync tests * Prettier changes * Rename variables to be more semantic * Prettier updates * Update test following review - Use beforeEach and afterEach to set up and tear down container element for use in each test - Move any functions specific to one test to within test body (improves readability imo) * Add coverage for getNodeFromInstance and implementation of getFiberCurrentPropsFromNode - After researching usage of getNodeFromInstance we can test getNodeFromInstance dispatching some events and asserting the id of the currentTarget - After checking git blame for getFiberCurrentPropsFromNode and reading through facebook#8607 I found a test that we can simplify to assert behavior of the function by ensuring event handler props are updated from the fiber props. Swapping out the implementation of this function with `return node[internalInstanceKey].memoizedProps` results in a failure.