-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
fix instance null when involve async destruction #6095
Conversation
componentWillUnmount: function() { | ||
var self = this; | ||
// some async animation | ||
setImmediate(function() { |
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.
setImmediate
shouldn't be used, since it means we will never be able to run these tests in a real browser. https://developer.mozilla.org/en-US/docs/Web/API/Window/setImmediate
Consider setTimeout
instead.
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.
setTimeout is mocked by jest, don't know how to simulate asynchronous in jest
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.
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.
I don't see a problem with this? You guys should upgrade to jasmine2 so you can use the done
feature of jasmine2 for async testing. Otherwise waitsFor
is fine, just ugly API. You can also do jest.runAllTimers()
to advance them manually – that way you can get rid of the waitsFor
.
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.
runAllTimers run function provided to setTimeout synchronously. This test case needs asynchronization
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.
what kind of async? You can also do jest.runAllImmediates
.
This looks fine to me ( 👍 ) , just one minor change requested. |
ae5e2d8
to
df095c0
Compare
After checking jest, use |
@yiminghe updated the pull request. |
ping @jimfb |
@yiminghe Thanks for the ping! And thanks for the PR, this looks great! Might even be able to squeeze it into v15! |
fix instance null when involve async destruction
see tests in
Files changed