Skip to content

Commit

Permalink
Add syncify helper for testing async functions that throw exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisronline committed Jan 12, 2018
1 parent 81b339d commit bf1abf5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
10 changes: 10 additions & 0 deletions src/test/syncify.js
Original file line number Diff line number Diff line change
@@ -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; };
}
};

0 comments on commit bf1abf5

Please sign in to comment.