Protractor / Jasmine

Related to this question: How can I create conditional test cases using Protractor? “I'm curious if there is a legitimate (documented) answer to these scenarios, because I cannot get a direct answer.”

While the solution ignoreposted in the related question works, stylistically I am not a fan of this. At first glance, it looks like you are ignoring / skipping the spec.

Also, I asked this question on Gitter - Is the following code a bad practice?

if(questionAnswer == "Yes") {
   it('should display another question', function() {
       // code
   });
}

The answer I got from Gitter from someone on the Protractor team was pretty vague:

this can lead to a disgust test ... I don’t think that everything that says is not a bad practice. If it works for you, then run with it.

I am not satisfied with this answer because it started with “maybe flaky” ... which does not look stable for me. The only alternative that I see is to create a conditional value inside the specification as normal and create an arbitrary statement to capture the script else, i.e.:

it('should display another question', function() {
    if(questionAnswer == "Yes") {
        expect(question2.isDisplayed()).toBe(true);
    }
    else {
        expect(true).toBe(true);
    }
});

But then I automatically add an additional test case when it needs only 50% of the time. I know this is a small problem, but it really bothers me.

- , . "", . , . Jasmine/Protractor?

+4
1

, . , .

Jasmine, BDD-, Rspec ( ). context describe.

, describe :

describe('someMethod', function() {
    describe('when a privileged account', function() {
        beforeEach(function() {
           questionAnswer = "Yes";
           someMethod();
        });

        it('should do something', function() {
            // expectation
        }
    });

    describe('when not a privileged account', function() {
        beforeEach(function() {
           questionAnswer = "No";
           someMethod();
        });

        it('should do something else', function() {
            // expectation
        }
    });
);

" ". , . , , , BDD-.

, - , . , . ...

+6

All Articles