提交 0b68b17c 编写于 作者: W Winnie Hellmann

Fail for unhandled Promise rejections in Jest

上级 0d26c483
......@@ -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();
}
}
......
......@@ -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();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册