Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update additional tests to use .toWarnDev() matcher #11957

Merged
merged 8 commits into from
Jan 3, 2018

Conversation

bvaughn
Copy link
Contributor

@bvaughn bvaughn commented Jan 3, 2018

Continuation of PR #11952

Update additional unit tests to use .toWarnDev() instead of console spies and if-DEV conditionals.

Note commit 806035a specifically, as it slightly tweaks a ReactElementValidator warning message to differentiate between Array and Object types. (Is this okay? Seems like an improvement- and since it's a dev-only warning, I don't think it's particularly unsafe.)

After this PR, only two files remain that spy on console:

  • packages/react-reconciler/src/tests/ReactIncrementalErrorLogging-test.internal.js
  • packages/react-dom/src/tests/utils/ReactDOMServerIntegrationTestUtils.js

Both are a little involved, so I'll handle them with a subsequent PR.

Note this test previous had some hacky logic to verify errors were reported against unique line numbers. Since the new matcher doesn't suppor this, I replaced this check with an equivalent (I think) comparison of unique DOM elements (eg div -> span)
… in its warning. Also updated its test to use .toWarnDev() matcher.
Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Left one comment where it’d be nice to figure out the original intention. Not a blocker though.


//verify line number has a proper relative difference,
//since hard coding the line number would make test too brittle
expect(parseInt(previousLine, 10) + 12).toBe(parseInt(currentLine, 10));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was intentional although I don’t remember what exactly it’s trying to verify. Maybe it’s not that important.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read the intent here as making sure that we warned about both issues with distinct component stacks (pointing to the right element for class and onclick). I'm not positive but that seemed to be the case. I approximated this by changing the element type and asserting with that instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like several of these lines were added by you a year ago 😅 with PR #8570

The others were added 2 years ago with PR #6398 in order to verify that our error message pointed to the correct component+line. (See issue #6062) I think the new approach I'm taking also satisfies this goal! So it should be okay. 👍

@bvaughn bvaughn merged commit 9f848f8 into facebook:master Jan 3, 2018
@bvaughn bvaughn deleted the toWarnDev-part-3 branch January 3, 2018 21:55
@bvaughn
Copy link
Contributor Author

bvaughn commented Jan 3, 2018

I should note that I believe there are only 2 things left to update for the new matcher. One of them, the ReactDOMServerINtegrationTestUtils (which is used by all the ReactDOMServerIntegration* tests) looks like it's going to be a huge pain in the ass. ☹️

@gaearon
Copy link
Collaborator

gaearon commented Jan 3, 2018

Here's an opportunity for you to simplify it 😄

(Seriously though, if you have ideas on how to make it better without exploding the whole suite to be 5x bigger and error-prone, let's do it)

@gaearon
Copy link
Collaborator

gaearon commented Jan 3, 2018

FWIW I'm also running into issues with warnings in the integration suite. Particularly with the fact that soon we'll need to pass different expected warning count for client and server, as I explained in #11956 (comment). If you can solve that while you port it to toWarnInDev, this will unblock Jest 22 migration (it's the last blocker).

@bvaughn
Copy link
Contributor Author

bvaughn commented Jan 3, 2018

I think I can slightly improve it (by using a variation of the new matcher) but I'm not sure if I want to take on the scope of refactoring all of those tests at the moment 😄

Cool. I'll add the other to my list of things to think about 👍

@bvaughn
Copy link
Contributor Author

bvaughn commented Jan 3, 2018

Actually I'm not sure how easy this is going to be to do after all, since Jest doesn't seem to support async custom matchers (jestjs/jest/issues/3874, jestjs/jest/issues/4223) and ReactDOMServerINtegrationTestUtils callbacks are async.

yenshih pushed a commit to yenshih/react that referenced this pull request Jan 6, 2018
* Migrated several additional tests to use new .toWarnDev() matcher

* Migrated ReactDOMComponent-test to use .toWarnDev() matcher

Note this test previous had some hacky logic to verify errors were reported against unique line numbers. Since the new matcher doesn't suppor this, I replaced this check with an equivalent (I think) comparison of unique DOM elements (eg div -> span)

* Updated several additional tests to use the new .toWarnDev() matcher

* Updated many more tests to use .toWarnDev()

* Updated several additional tests to use .toWarnDev() matcher

* Updated ReactElementValidator to distinguish between Array and Object in its warning. Also updated its test to use .toWarnDev() matcher.

* Updated a couple of additional tests

* Removed unused normalizeCodeLocInfo() methods
NMinhNguyen referenced this pull request in enzymejs/react-shallow-renderer Jan 29, 2020
* Migrated several additional tests to use new .toWarnDev() matcher

* Migrated ReactDOMComponent-test to use .toWarnDev() matcher

Note this test previous had some hacky logic to verify errors were reported against unique line numbers. Since the new matcher doesn't suppor this, I replaced this check with an equivalent (I think) comparison of unique DOM elements (eg div -> span)

* Updated several additional tests to use the new .toWarnDev() matcher

* Updated many more tests to use .toWarnDev()

* Updated several additional tests to use .toWarnDev() matcher

* Updated ReactElementValidator to distinguish between Array and Object in its warning. Also updated its test to use .toWarnDev() matcher.

* Updated a couple of additional tests

* Removed unused normalizeCodeLocInfo() methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants