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/frontend/environment.js | |
parent | 0d26c48332e7c580946adbd41795d4817909e2ef (diff) | |
download | gitlab-ce-0b68b17c3bf5d93fe942eed2ef0d16b6824f5499.tar.gz |
Fail for unhandled Promise rejections in Jest
Diffstat (limited to 'spec/frontend/environment.js')
-rw-r--r-- | spec/frontend/environment.js | 19 |
1 files changed, 19 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(); } } |