-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Throw assertion does not catch class constructor errors #739
Comments
You need to wrap any statement in a function. It's not possible for us to catch the Error otherwise. For one liners like that, arrow functions are where it's at: test("Expect FeedAggregator to throw error when subclass has no getItems method", t => {
t.throws(
() => new BadAggregator({feedName: 'test', feedType: 'test'}),
TypeError("Class must define a getItems method")
);
}); |
Thanks. |
jamestalmage
added a commit
to jamestalmage/ava
that referenced
this issue
Apr 9, 2016
Protects against a common misuse of t.throws (Like that seen in avajs#739). This required the creation of a custom babel plugin. https://github.com/jamestalmage/babel-plugin-ava-throws-helper
jamestalmage
added a commit
that referenced
this issue
Apr 11, 2016
* detect improper use of t.throws Protects against a common misuse of t.throws (Like that seen in #739). This required the creation of a custom babel plugin. https://github.com/jamestalmage/babel-plugin-ava-throws-helper * relative file path and colors * protect against null/undefined in _setAssertError * use babel-code-frame to do syntax highlighting on the Error * require `babel-code-frame` inline. It has a sizable dependency graph * remove middle section of message. It is redundant given code-frame * further tests and add documentation. * update readme.md
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use case: An abstract class which implements member checking in the constructor.
Example:
Expected output:
Actual output:
The text was updated successfully, but these errors were encountered: