Feature: An opposite version of `expect`
BennieCopeland opened this issue · comments
Is there a way to test that an exception is NOT thrown? Right now, I'm using:
it["will not throw an excpection"] = () => { };
It works... there is the exception text in red at the bottom of the console output, but the test itself remains green. We can add this to my list of things to implement when I find the time.
I think this somewhat ties into issue #135 since what I'm looking for is the example to show red when the act
throws an exception (or really any setup).
@BennieCopeland PR #192 has been merged just in these days. There were some inconsistencies when an exception was thrown in some of the hooks and that also led to what you noticed (the exception was actually reported in the final summary as well as failure count, but the test itself remained green).
I think we fixed such behaviour with that PR, so I'm wondering if expectNoExceptions
is still really needed. If you temporarily edit describe_expecting_no_exception_in_act
and replace expectNoExceptions
with () => { }
, you can see that the TestCase fails only because of the message: it expects a failure due to "example" but instead it finds a failure due to "context". Which makes sense I guess, given that the error is not happening within the it
block, but in a previous (act) hook.
Any thought?
May be worth looking at this code example too.
@GiuseppePiscopo If the behavior has changed to fail the tests when a beforeEach/beforeAll/act throws an exception, then yes, I agree this is no longer needed.
Yes, it has definitely changed. As a matter of fact now, with the test cases you added, replacing expectNoExceptions
with () => { }
:
should_be_one_failure
passespasses_if_no_exception_thrown
passesrethrows_the_exception_from_act
fails because of the different message. That is consistent, for me, and I'd alter this expectation to make it pass.
Thanks for your feedback