Skip to content

Commit 1bf1bba

Browse files
fix(waitFor) leaking callback
1 parent a7b7252 commit 1bf1bba

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/wait-for.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function copyStackTrace(target, source) {
1616
}
1717

1818
function waitFor(
19-
callback,
19+
originalCallback,
2020
{
2121
container = getDocument(),
2222
timeout = getConfig().asyncUtilTimeout,
@@ -41,6 +41,10 @@ function waitFor(
4141
throw new TypeError('Received `callback` arg must be a function')
4242
}
4343

44+
// callback will be replaced by a noop function as soon as it finishes
45+
// to prevent callback leaking calls
46+
let callback = originalCallback;
47+
4448
return new Promise(async (resolve, reject) => {
4549
let lastError, intervalId, observer
4650
let finished = false
@@ -107,6 +111,7 @@ function waitFor(
107111

108112
function onDone(error, result) {
109113
finished = true
114+
callback = () => {};
110115
clearTimeout(overallTimeoutTimer)
111116

112117
if (!usingJestFakeTimers) {

0 commit comments

Comments
 (0)