Skip to content

Add syncify test helper#301

Merged
chrisronline merged 3 commits intoelastic:masterfrom
chrisronline:add-syncify-test-helper
Jan 12, 2018
Merged

Add syncify test helper#301
chrisronline merged 3 commits intoelastic:masterfrom
chrisronline:add-syncify-test-helper

Conversation

@chrisronline
Copy link
Contributor

@cjcenizal recommended adding this from this discussion

This helper allows you to properly test async functions that throw exceptions.

Here is working code using the helper:

const fn = await syncify(() => asyncFn());
expect(fn).toThrow();

@chrisronline chrisronline self-assigned this Jan 12, 2018
Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just one request.

@@ -0,0 +1,10 @@
// Helper designed to help test async/await functions that throw exceptions
// https://github.com/facebook/jest/issues/1377
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add your example code to this comment:

Example usage:
const fn = await syncify(() => asyncFn());
expect(fn).toThrow();

@cjcenizal
Copy link
Contributor

Oh and can you add a note to the CHANGELOG.md?

@chrisronline
Copy link
Contributor Author

Done!

@chrisronline chrisronline merged commit 4decff2 into elastic:master Jan 12, 2018
@chrisronline chrisronline deleted the add-syncify-test-helper branch January 12, 2018 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants