summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWinnie Hellmann <winnie@gitlab.com>2019-07-08 13:15:32 +0200
committerWinnie Hellmann <winnie@gitlab.com>2019-07-08 13:15:32 +0200
commit85aaf5552d97c230d4569f45af6ffd14cecab676 (patch)
tree0a05c4b1e4eae11215aca675c258537ed9f0b36f
parent4f6ec719a2c49472591b28455f909e3d6800923c (diff)
downloadgitlab-ce-winh-fail-pending-timers-jest.tar.gz
Fail for pending timers in Jestwinh-fail-pending-timers-jest
-rw-r--r--spec/frontend/test_setup.js14
1 files changed, 13 insertions, 1 deletions
diff --git a/spec/frontend/test_setup.js b/spec/frontend/test_setup.js
index 15cf18700ed..a81a4e4b4f4 100644
--- a/spec/frontend/test_setup.js
+++ b/spec/frontend/test_setup.js
@@ -18,7 +18,19 @@ afterEach(() =>
// give Promises a bit more time so they fail the right test
new Promise(setImmediate).then(() => {
// wait for pending setTimeout()s
- jest.runAllTimers();
+ for (let i = 0; i < 3; i += 1) {
+ jest.runOnlyPendingTimers();
+ jest.runAllTicks();
+ jest.runAllImmediates();
+ }
+
+ const numPendingTimers = jest.getTimerCount();
+ if (numPendingTimers > 0) {
+ jest.clearAllTimers();
+ throw new Error(`There are ${numPendingTimers} pending timers left. Make sure to run or clear them.
+
+see also https://jestjs.io/docs/en/timer-mocks`);
+ }
}),
);