0

it()そのため、ブロック内の関数describe()は (常に) 記述した順序で実行されないことに気付きました。

それらは非同期ですか?そして、それらを特定の順序で強制的に実行する方法は?

it()一連の UI ミューテーションを連鎖させ、基本的に各関数で前のステップの後に UI の状態をチェックさせたいと考えています。

それらが非同期で実行される場合、そのようなことは要点を打ち負かします。つまり、各it()ブロックには前のブロックのすべてのステップを含める必要があるということですか?

it('should do something', function() {
  // app is in state 1
  // do something
  // leave app in state 2
});
it('should continue from the state left after the previous block', function() {
  // app is in state 2
  // do something
  // leave app in state 3
});
it('should continue from the state left after the previous block', function() {
  // app is in state 3
  // do something
  // leave app in state 4
});
it('should continue from the state left after the previous block', function() {
  // app is in state 4
  // do something
  // leave app in state 5
});
...
4

1 に答える 1

3

「it」関数内のすべてが独立したテストです。あなたがする必要があるのは、共有ステップを「beforeEach」関数に入れることです

describe('Check pdf popup', function() {
    beforeEach(function() {
        element('.navbar a:eq(3)').click();
    });

    it('We should see the pdf popup', function() {
        expect(element('.modal h4:visible').text()).toMatch(/Email PDF/);
    });

    it('Cancel should dispel the pdf popup', function() {
        // exit pdf box
        element('input[value="Cancel"]').click();
        expect(repeater('.modal h4:visible').count()).toBe(0);
    });

    it('if customer email not set, display input for email', function() {
        expect(repeater('.modal #pdfemail:visible').count()).toBe(1);
        expect(repeater('.modal #pdfcustomercheckbox:visible').count()).toBe(0);
    });

});

連続したコマンドを発行する効果を持つ、追加の「beforeEach」関数を含む、追加の「describe」ブロックを相互にネストできます。

describe('fuel comparison', function() {
    beforeEach(function() {
        element("#gasvsdiesel").click();
    });

    it('should switch to Fuel Comparison calculator', function() {
        expect(element('.brand').text()).
            toBe("Fuel Comparison");
    });

    describe('changing gas price', function() {
        beforeEach(function() {
            input("compareFuelPrice").enter("5.888");
        });

        it('should change fuelinfo text to show reset link', function() {
            element('#content .nav-pills a[tap-click="tab=\'calculations\'"]').click();
            expect(element("#fuelinfo span:visible").text()).toBe("(Click here to set fuel prices to California defaults)");
        });

    });
   });
于 2013-06-30T20:45:33.180 に答える