mocha-cakes-2
mocha-cakes-2 copied to clipboard
Skip remaining tests when a `Given` or `When` fails
I love the semantics this library adds to my tests.
In particular, I love how this allows me to write "sequential steps", which are clearly dependent on each other. For example:
Given("I have an apple", ...);
When("I eat the apple", ...);
Then("I feel full", ...);
And("I feel healthy", ...);
This gives me very clear "arrange", "act", and "assert" sections (Given, When, Then
).
Now imagine that one of my "arrange" or "act" steps fails -- eg. I fail to "eat the apple".
Unfortunately, this results in 3 failed tests.
However, that's not quite what I expect. When an "arrange" or "act" fails, I would expect the "assertions" to be skipped. In other words, if a Given
or When
fails, all Thens
should be skipped. And / But
would probably be best categorized based on what preceded them.
Does this make sense? I half-expected this to be the existing behavior, but a quick test reveals that if any Given/When
fails, the rest of the assertions are still executed (which often gives confusing results).
Hi!
Thank you for your issue. I agree that it would be a nice to have feature. However, I believe this might be a bit tricky to achieve. I will look into it when I get some time over. If you have a clear idea of how to implement it feel free to create a PR :)
Running mocha with the --bail
flag will stop the test suite as soon as an assertion fails. Not really what you are after perhaps, but anyway. :)
Totally agree
I've made this small plug-in to address this issue: https://gist.github.com/Lautenschlager-id/b2852091e72f4ade94c6212aa510f7b9
Sadly it's a bit too high level to be implemented in the source of mocha-cakes-2 I'm afraid.