admin管理员组文章数量:1391929
My jasmine2/protractor test look like this
var testUserId = null;
describe("user test", function() {
beforeAll(function(done) {
createTestUser().
.then(function(userId){testUserId = userId})
.then(done)
.catch(done.fail);
it("should do stuff with the test user", function(done) {
// bla bla
});
afterAll(function(done) {
deleteTestUser(testUserId).
.then(done)
.catch(done.fail);
});
})
createTestUser and deleteTestUser return promises. If a problem occur they reject with an error message. May Problem is now, that the tests get started even if the error occurs in beforeAll. And I get
Failures:
1) should do stuff with the test user
Message: [my error message from beforeAll]
If there are many tests it tries to perform all of them and fail with the very sam error message. Is it possible to prevent it from executing the tests if the beforeAll function fails?
Thx!
("jasmine-core": "2.8.0", "protractor": "5.2.1")
Edit:
It's not exactly what I was asking for but at least I found a solution to keep the amount of error messages close like this:
var testUserId = null;
describe("user test", function() {
beforeAll(function(done) {
createTestUser().
.then(function(userId){testUserId = userId})
.then(done)
.catch(done.fail("test user could not be created"));
it("should do stuff with the test user", function(done) {
if (testUserId) {
// bla bla
} else {
done();
});
This way I get a least only the correct error message ("test user could not be created") and not the ones of the unmet expectations in "// bla bla" (Naturally I still get one for each it, but whatever). I also wrapped the functions in a function-factory so that I don't have to write the if-condition everytime.
My jasmine2/protractor test look like this
var testUserId = null;
describe("user test", function() {
beforeAll(function(done) {
createTestUser().
.then(function(userId){testUserId = userId})
.then(done)
.catch(done.fail);
it("should do stuff with the test user", function(done) {
// bla bla
});
afterAll(function(done) {
deleteTestUser(testUserId).
.then(done)
.catch(done.fail);
});
})
createTestUser and deleteTestUser return promises. If a problem occur they reject with an error message. May Problem is now, that the tests get started even if the error occurs in beforeAll. And I get
Failures:
1) should do stuff with the test user
Message: [my error message from beforeAll]
If there are many tests it tries to perform all of them and fail with the very sam error message. Is it possible to prevent it from executing the tests if the beforeAll function fails?
Thx!
("jasmine-core": "2.8.0", "protractor": "5.2.1")
Edit:
It's not exactly what I was asking for but at least I found a solution to keep the amount of error messages close like this:
var testUserId = null;
describe("user test", function() {
beforeAll(function(done) {
createTestUser().
.then(function(userId){testUserId = userId})
.then(done)
.catch(done.fail("test user could not be created"));
it("should do stuff with the test user", function(done) {
if (testUserId) {
// bla bla
} else {
done();
});
This way I get a least only the correct error message ("test user could not be created") and not the ones of the unmet expectations in "// bla bla" (Naturally I still get one for each it, but whatever). I also wrapped the functions in a function-factory so that I don't have to write the if-condition everytime.
Share Improve this question edited Jan 4, 2018 at 15:26 Paflow asked Dec 18, 2017 at 16:19 PaflowPaflow 2,3875 gold badges34 silver badges58 bronze badges 3-
why aren't you mocking the dependency that
createTestUser
creates? a test shouldn't fail because a dependency failed. isolate yourself! – Daniel A. White Commented Dec 18, 2017 at 16:23 - Thats right. Let's just say it would mean a way too big change in an architecture which is not made by me. In the realz there is not only a testuser created but many other stuff, but a uses a real backend with database and stuff for that and this might go wrong. yes, yes, I know.. – Paflow Commented Dec 18, 2017 at 16:48
- it sounds like an x-y problem then. you can do anything with the items in your test. – Daniel A. White Commented Dec 18, 2017 at 16:49
1 Answer
Reset to default 5From what I understand, jasmine
does not support that despite the attention:
Skipping out in the middle of the spec run (this issue) is a bit more plicated, because depending on the type of error, Jasmine probably still needs to run any afterEach (or afterAll depending) to cleanup state for the next spec. This would then require the QueueRunner to know which of the functions it is given are setup and teardown and not just have a list of functions to call.
One option would be to use the "fail fast" option which can be done by using one of the third-party libraries like jasmine-fail-fast
or protractor-jasmine2-fail-whale
.
There are though some other workarounds, like manually checking if there was a preceding failure in the it()
functions:
- Jasmine/Protractor: stop test on failure in beforeEach
本文标签: javascriptjasmine2 how to handle failing beforeAllStack Overflow
版权声明:本文标题:javascript - jasmine2: how to handle failing beforeAll - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744713281a2621254.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论