-
Notifications
You must be signed in to change notification settings - Fork 47.4k
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
Fixed potential false-positive in toWarnDev matcher #11898
Conversation
scripts/jest/setupTests.js
Outdated
const noop = function() {}; | ||
const spyOn = function(object, methodName) { | ||
if (object === console) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: Some of our tests spy on console.log
(eg ReactDOMComponent-test
) so this would also need to check if methodName === "warn" || methodName === "error"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also change them to use jest.fn
or something directly.
9dbe23c
to
5880076
Compare
Also updated (most of) ReactIncrementalErrorLogging-test.internal to use the new matcher
988f976
to
1a8c80e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense to me
* Warn about spying on the console * Added suppress warning flag for spyOn(console) * Nits * Removed spy-on-console guard * Fixed a potential source of false-positives in toWarnDev() matcher Also updated (most of) ReactIncrementalErrorLogging-test.internal to use the new matcher * Removed unused third param to spyOn * Improved clarity of inline comments * Removed unused normalizeCodeLocInfo() method
* Warn about spying on the console * Added suppress warning flag for spyOn(console) * Nits * Removed spy-on-console guard * Fixed a potential source of false-positives in toWarnDev() matcher Also updated (most of) ReactIncrementalErrorLogging-test.internal to use the new matcher * Removed unused third param to spyOn * Improved clarity of inline comments * Removed unused normalizeCodeLocInfo() method
Spying on(This has been removed.)console.error
orconsole.warn
will now fail tests by default, with an error suggesting the use of the newtoWarnDev
matcher instead.Updated
.toWarnDev()
matcher to report a failed expectation to Jest even if anError
was thrown by its callback. Giving precedence to failed expectations prevents a thrown error from potentially masking failed expectations (and removes a source of potential false-positives from our tests).As of this point, all but 2 of our tests have been updated to the new matcher:
ReactIncrementalErrorLogging-test.internal
: There's one test case that I'm unsure of how to update. I'll look at it again tomorrow.ReactDOMServerIntegrationTestUtils
: It's possible to update this test util but it will take time since several, procedurally-generated tests use it. For the time being, I've added a TODO comment for following up on it.