Jasminejs-aftereach

提供:Dev Guides
移動先:案内検索

JasmineJS-afterEach()

beforeEach()と同様に、afterEach()はまったく同じように機能します。 specブロックの実行後に実行されます。 次のコードを使用して前の例を変更しましょう。

var currentVal = 0;

afterEach(function() {
   currentVal = 5;
});

describe("Different Methods of Expect Block",function() {
   it("first call ", function() {
      expect(currentVal).toEqual(0);
   });

   it("second call ",  function() {
      expect(currentVal).toEqual(5);
   });
});

上記の例では、最初のspecブロックの実行中、 currentVal の値は0です。 したがって、テストケースに合格しますが、最初のitブロックを実行した後、Jasmine compileはafterEach()ブロックを実行しました。これにより、currentValの値が5になります。 したがって、2番目のケースも満たし、出力として緑色のスクリーンショットを生成します。

AfterEach