-
Notifications
You must be signed in to change notification settings - Fork 470
fix: Stop calling waitFor
callback after timeout
#1271
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
Changes from 1 commit
a0bb005
6b41483
55ff2f2
67793f8
86c5c08
ce11c0f
10a1ac7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,6 +106,9 @@ function waitFor( | |
} | ||
|
||
function onDone(error, result) { | ||
if (finished) { | ||
return | ||
} | ||
finished = true | ||
clearTimeout(overallTimeoutTimer) | ||
|
||
|
@@ -134,7 +137,7 @@ function waitFor( | |
} | ||
|
||
function checkCallback() { | ||
if (promiseStatus === 'pending') return | ||
if (finished || promiseStatus === 'pending') return | ||
try { | ||
const result = runWithExpensiveErrorDiagnosticsDisabled(callback) | ||
if (typeof result?.then === 'function') { | ||
|
@@ -160,6 +163,9 @@ function waitFor( | |
} | ||
|
||
function handleTimeout() { | ||
if (finished) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we cancel the timeout instead when we finish? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When we finish, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Amended in 6b41483 |
||
return | ||
} | ||
let error | ||
if (lastError) { | ||
error = lastError | ||
|
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.
Can we cancel whatever is calling
checkCallback
instead?Uh oh!
There was an error while loading. Please reload this page.
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 would love to, but I'm afraid it might introduce breaking changes.
We'll need to move the
if(finished)
beforecheckCallback
here: https://github.com/testing-library/dom-testing-library/pull/1271/files#diff-68584107d5f50eb95702a47b23bb6e0f6c2d78f9bab7456a1a4150c79229db78R84-R92But the following comment is daunting:
dom-testing-library/src/wait-for.js
Lines 84 to 87 in a0bb005
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.
Actually https://github.com/testing-library/dom-testing-library/pull/1271/files#diff-68584107d5f50eb95702a47b23bb6e0f6c2d78f9bab7456a1a4150c79229db78R84-R92 is un-related, so I should move the
if(finished)
beforecheckCallback
👍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.
Amended in 6b41483