Skip to content
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

Assertion 'to throw' does not work #411

Closed
JakubMatejka opened this issue Jul 25, 2017 · 5 comments
Closed

Assertion 'to throw' does not work #411

JakubMatejka opened this issue Jul 25, 2017 · 5 comments

Comments

@JakubMatejka
Copy link

JakubMatejka commented Jul 25, 2017

Assertions 'to throw', 'to error' and 'to throw a' does not work and the test fails on the thrown error instead. Maybe the problem could be that I throw subclass of the Error class? (But 'to throw a' does not work either so I don't know.)

usererror js 2017-07-25 12-08-45

@papandreou
Copy link
Member

The correct usage of to throw would be:

.then(() => expect(() => projects.create(createEvent2), 'to throw'))

We should try to make that clearer in the docs.

Tangentially related: #395

@sunesimonsen
Copy link
Member

Hi thanks for the issue. Could it be that the create method throws an exception instead of returning a rejected promise? If so the expect statement have no way of catching that as the method arguments will be evaluated before the method invocation. "to throw" works by invoking it's first parameter and expecting that it will throw an exception. Try to see if the examples in the documentation will clear things up http://unexpected.js.org/assertions/function/to-throw/

@JakubMatejka
Copy link
Author

JakubMatejka commented Jul 26, 2017

Oh, thank you, the suggestion by @papandreou works.

And yes, the create method consists of calling an external method (which throws the exception) and then returns a chain of promises. So I guess I should rather put the sync method to a promise chain too. Thanks @sunesimonsen for the explanation.

@sunesimonsen
Copy link
Member

sunesimonsen commented Jul 26, 2017 via email

@ezmiller
Copy link

Would be great if the docs could be improved to make the distinction that @papandreou describes clear...

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

No branches or pull requests

4 participants