diff --git a/src/test/index.js b/src/test/index.js index af1224e7b7b..616df81665c 100644 --- a/src/test/index.js +++ b/src/test/index.js @@ -2,3 +2,4 @@ export { requiredProps } from './required_props'; export { takeMountedSnapshot } from './take_mounted_snapshot'; export { findTestSubject } from './find_test_subject'; export { startThrowingReactWarnings, stopThrowingReactWarnings } from './react_warnings'; +export { syncify } from './syncify'; diff --git a/src/test/syncify.js b/src/test/syncify.js new file mode 100644 index 00000000000..e28f0f1d6f1 --- /dev/null +++ b/src/test/syncify.js @@ -0,0 +1,10 @@ +// Helper designed to help test async/await functions that throw exceptions +// https://github.com/facebook/jest/issues/1377 +export const syncify = async (fn) => { + try { + const result = await fn(); + return () => { return result; }; + } catch (e) { + return () => { throw e; }; + } +};