Skip to content

Express more tests via public API #11299

Closed

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.


Activity

  1. jeremenichelli commented on Oct 20, 2017

    @jeremenichelli
    Contributor

    I can take a look at this over the weekend and see if I can tackle it in the short term.

  2. gaearon commented on Oct 20, 2017

    @gaearon
    CollaboratorAuthor

    Great, thanks! If you pick any particular test, please comment with the filename in the thread so that someone else doesn’t start working on the same test.

  3. arielsilvestri commented on Oct 20, 2017

    @arielsilvestri

    I am definitely very interested in contributing to this. I will look through this weekend and find an opportunity to refactor!

  4. SadPandaBear commented on Oct 20, 2017

    @SadPandaBear
    Contributor

    I am interested as well 👍

  5. gaearon commented on Oct 20, 2017

    @gaearon
    CollaboratorAuthor

    I published a list of tests in the first post. Just let me know which ones you’d like to take and I’ll assign them to you.

  6. SadPandaBear commented on Oct 20, 2017

    @SadPandaBear
    Contributor

    ReactDOMInput-test is fine with me :)

  7. gaearon commented on Oct 20, 2017

    @gaearon
    CollaboratorAuthor

    @SadPandaBear You got it!

  8. reznord commented on Oct 20, 2017

    @reznord
    Contributor

    I can work on ReactErrorUtils-test. 😄

  9. arielsilvestri commented on Oct 20, 2017

    @arielsilvestri

    I will take a look at setInnerHTML-test.js

  10. jamie-wk commented on Oct 20, 2017

    @jamie-wk

    I'll do getEventCharCode-test.js. 😀

  11. mwilc0x commented on Oct 20, 2017

    @mwilc0x
    Contributor

    I can work on getEventKey-test.js.

  12. 170 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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