Skip to content

Express more tests via public API #11299

@gaearon

Description

@gaearon

This is a great contribution opportunity.
We need to rewrite more unit tests in terms of public API.

This means that they can only import npm entry points like react, react-dom, react-dom/test-utils, react-test-renderer, etc, but not internal modules like SyntheticEvent or ReactDOMComponentTree. The “bad” requires are already marked with a TODO in tests so you won’t miss them.

To help with this:

  1. Find // TODO: can we express this test with only public API? in the unclaimed test files below.
  2. Comment in this issue if you want to take a particular unit test file, with its name.
  3. Submit a PR that rewrites the test to use public APIs instead.

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.


Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions