Skip to content

Commit

Permalink
Add syncify test helper (#301)
Browse files Browse the repository at this point in the history
* Add syncify helper for testing async functions that throw exceptions

* Add comment

* Add to changelog
  • Loading branch information
chrisronline authored Jan 12, 2018
1 parent 81b339d commit 4decff2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Added small version of `EuiCallOut` [(#269)](https://github.com/elastic/eui/pull/269)
- Added first batch of TypeScript type definitions for components and services [(#252)](https://github.com/elastic/eui/pull/252)
- Added button for expanding `<EuiCodeBlock>` instances to be full-screen. [(#259)](https://github.com/elastic/eui/pull/259)
- Add test helper for async functions that throw exceptions [#301](https://github.com/elastic/eui/pull/301)

**Bug fixes**

Expand Down
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';
13 changes: 13 additions & 0 deletions src/test/syncify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Helper designed to help test async/await functions that throw exceptions
// Example usage:
// const fn = await syncify(() => asyncFn());
// expect(fn).toThrow();
// 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 4decff2

Please sign in to comment.