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
Stop testcase execution on failure in beforeEach #577
Comments
Having a manual way of stopping a test case execution would be really handy. For example when creating tests for Selenium Webdriver and during the flow for example login fails thus I cannot perform rest of my steps I could fail the test with predefined message and skip the rest of the execution and jump to next one. |
Is a manual fail method sufficient? If so, we have this in our backlog. |
I don't think the manual fail method solves this by itself. It sounds to me like the desired behavior is that a single spec stops execution upon encountering its first expectation failure or exception and proceeds straight to the next spec. This would probably need to be some other kind of option to jasmine similar to whats requested in #414 but for a single spec instead of the whole suite. I'm not sure what we would want to do as far as |
I've created a set of stories in tracker that detail how we want to address this issue.
We'd be happy to review pull requests for this functionality. Thanks for using jasmine! |
[finish #1165916] jasmine#577
+1. Now this is weird behavior. If I have a failed setup in beforeEach, all my tests would be incorrect. Why do you execute this test cases anyway? |
Sorry, do I understand this correctly: if I call |
Just ran into this, the behavior is a bit outside of expectation IMO. We have a |
Adding to the voices here... fail("Some message");
expect(false).toBe(true); Definitely does not make sense to continue execution after the fail above, whether in a test or a But in the interests of making this a backwards compatible change (i.e. no surprises for people who may be relying on this behaviour), would a new function |
@myitcv this feature isn't just about when you call fail, but also when an expectation fails. We've done a little work to get closer to this desired functionality, but we're not quite there yet. We would still be happy to review a pull request that makes this happen. |
@slackersoft - thanks for the response. Sounds like you've considered the case of calling |
+1. Any progress on this? |
This is a real issue. Just spent half a day trying to understand why my tests were failing because angular was throwing an exception on an unknown module loaded in a beforeEach but nothing was shown in the logs. Had to instrument angular with |
@LukeSkyw I think you might be conflating something like #529 with this issue. If your exception makes it up to Jasmine, your spec will be marked as failed with that error. However, Jasmine continues with the rest of the execution queue of |
+1, this would be handy |
@slackersoft |
Actually my requirement is to skip the other cases/specs in the same suite if some critical case fails. I'm studying the code to see if there is some light-weight approach. |
@skyshore2001 Jasmine definitely does not want to have specific specs/suite marked as "critical". We would be happy to review a pull request for #414 to stop suite execution at the end of the first failing spec. Skipping out in the middle of the spec run (this issue) is a bit more complicated, because depending on the type of error, Jasmine probably still needs to run any |
@slackersoft couldn't |
This feature was released in version 2.7 of Jasmine-Core. If you don't have it, please update your dependency. Thanks for using Jasmine! |
For future googlers that might land on this issue - see |
I'm getting bit really hard by these issues: - jestjs/jest#2713 - jasmine/jasmine#577 - jasmine/jasmine#529
I'm getting bit really hard by these issues: - jestjs/jest#2713 - jasmine/jasmine#577 - jasmine/jasmine#529
Despite the issue being closed, I want to note that I am still seeing initial wrong behaviour with Code: describe("Feature", function () {
beforeEach(function () {
console.log("beforeEach");
throw new Error("");
});
it("Test 1", function () {
console.log("Test 1");
});
it("Test 2", function () {
console.log("Test 2");
});
}); Console output:
|
@korobochka I was only able to reproduce your output with
|
@sgravrock Yes, you are right. Sorry for confusion. |
I think it would be very useful to stop execution of a testcase if the beforeEach fails (i.e. throws an exception or similar).
Example: precondition is used for login -> if the login does not succeed, it does not make any sense to run the actual test.
I already tried to expect() something in the beforeEach (or in a function that it calls, to be more exact), and throwing an exception. The first did not work at all for my purposes (as other steps in the beforeEach were still executed), the 2nd at least registers as an error but the execution still continues.
Or maybe something like an option to stop executing the testcase as soon as one expectation fails could work, but I didn't find any such option.
The text was updated successfully, but these errors were encountered: