summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--spec/frontend/environment.js19
-rw-r--r--spec/frontend/test_setup.js2
2 files changed, 21 insertions, 0 deletions
diff --git a/spec/frontend/environment.js b/spec/frontend/environment.js
index 1067a53906a..34df8019a2e 100644
--- a/spec/frontend/environment.js
+++ b/spec/frontend/environment.js
@@ -27,6 +27,25 @@ class CustomEnvironment extends JSDOMEnvironment {
this.global.gon = {
ee: testEnvironmentOptions.IS_EE,
};
+
+ this.rejectedPromises = [];
+
+ this.global.promiseRejectionHandler = error => {
+ this.rejectedPromises.push(error);
+ };
+ }
+
+ async teardown() {
+ await new Promise(setImmediate);
+
+ if (this.rejectedPromises.length > 0) {
+ throw new ErrorWithStack(
+ `Unhandled Promise rejections: ${this.rejectedPromises.join(', ')}`,
+ this.teardown,
+ );
+ }
+
+ await super.teardown();
}
}
diff --git a/spec/frontend/test_setup.js b/spec/frontend/test_setup.js
index 006fc60ef57..00d7873ab2b 100644
--- a/spec/frontend/test_setup.js
+++ b/spec/frontend/test_setup.js
@@ -3,6 +3,8 @@ import Translate from '~/vue_shared/translate';
import axios from '~/lib/utils/axios_utils';
import { initializeTestTimeout } from './helpers/timeout';
+process.on('unhandledRejection', global.promiseRejectionHandler);
+
// wait for pending setTimeout()s
afterEach(() => {
jest.runAllTimers();