diff options
author | Winnie Hellmann <winnie@gitlab.com> | 2019-03-25 21:15:25 +0100 |
---|---|---|
committer | Winnie Hellmann <winnie@gitlab.com> | 2019-03-29 11:53:17 +0100 |
commit | 0b68b17c3bf5d93fe942eed2ef0d16b6824f5499 (patch) | |
tree | 16cf6fd3545fbd0475bb4e28de3ec1a9d54006fa /spec | |
parent | 0d26c48332e7c580946adbd41795d4817909e2ef (diff) | |
download | gitlab-ce-0b68b17c3bf5d93fe942eed2ef0d16b6824f5499.tar.gz |
Fail for unhandled Promise rejections in Jest
Diffstat (limited to 'spec')
-rw-r--r-- | spec/frontend/environment.js | 19 | ||||
-rw-r--r-- | spec/frontend/test_setup.js | 2 |
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(); |