Stop jasmine test after first expect fails

耗尽温柔 提交于 2019-12-28 03:04:52

问题


I'm familiar with python unittest tests where if an assertion fails, that test is marked as "failed" and it moves on to other tests. Jasmine on the other hand will continue through all expects even if the one of them fails. How can I make Jasmine stop processing a test after the first expectation fails?

it ("shouldn't need to test other expects if the first fails", function() {
    expect(array.length).toBe(1);

    // don't need to check this if the first failed.
    expect(array[0]).toBe("foo");
});

Am I thinking about it wrong? I have some tests with lots of expect's and it seems like a waste to show all the stack traces when only the first is wrong really.


回答1:


Jasmine doesn't support failing early, in a single spec. The idea is to give you all of the failures in case that helps figure out what is really wrong in your spec.




回答2:


@Gregg's answer was correct for the latest version of Jasmine at that time (v2.0.0).

However, since then, this new feature was added in v2.3.0:

Allow user to stop a specs execution when an expectation fails (Fixes #577)

It's activated by adding throwFailures=true to the query string of the runner page, eg:

http://localhost:8000/?throwFailures=true



回答3:


According to the comments of https://github.com/jasmine/jasmine/issues/414 I figured out that 2 solutions exists for this: https://github.com/radialanalytics/protractor-jasmine2-fail-whale https://github.com/Updater/jasmine-fail-fast

I just started to use the protractor-jasmine2-fail-whale because it seems to have more features. Although to take screenshots in case of test failures I currently use protractor-jasmine2-html-reporter.



来源:https://stackoverflow.com/questions/22119193/stop-jasmine-test-after-first-expect-fails

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!