Jasminejs-skip-block

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

JasmineJS-ブロックをスキップ

Jasmineでは、開発者が1つまたは複数のテストケースをスキップすることもできます。 これらの手法は、仕様レベル*または*スイートレベル*で適用できます。 アプリケーションのレベルに応じて、このブロックはそれぞれ *Skipping Spec および Skipping Suite として呼び出すことができます。

次の例では、“ x” *文字を使用して特定の *Spec または Suite をスキップする方法を学習します。

仕様をスキップ

*it* ステートメントの直前に*“ x” *を使用して前の例を変更します。
describe('This custom matcher example ', function() {

   beforeEach(function() {
     //We should add custom matched in beforeEach() function.

      jasmine.addMatchers({
         validateAge: function() {
            return {
               compare: function(actual,expected) {
                 var result = {};
                 result.pass = (actual > = 13 && actual < = 19);
                 result.message = 'sorry u are not a teen ';
                 return result;
               }
            };
         }
      });
   });

   it('Lets see whether u are teen or not', function() {
      var myAge = 14;
      expect(myAge).validateAge();
   });

   xit('Lets see whether u are teen or not ', function() {
     //Skipping this Spec
      var yourAge = 18;
   });
});

このJavaScriptコードを実行すると、結果としてブラウザーで次の出力を受け取ります。 ジャスミン自体は、特定の it ブロックが*“ xit” *を使用して一時的に*無効*になっていることをユーザーに通知します。

XITブロック結果

スキップスイート

同様に、 Skipping Suite のテクニックを実装するために、describeブロックを無効にすることができます。 次の例では、スイートブロックをスキップするプロセスについて学習します。

xdescribe('This custom matcher example ', function() {

  //Skipping the entire describe  block
   beforeEach(function() {

     //We should add custom matched in beforeEach() function.
      jasmine.addMatchers({
         validateAge: function() {
            return {
               compare: function(actual,expected) {
                 var result = {};
                 result.pass = (actual >=13 && actual<=19);
                 result.message ='sorry u are not a teen ';
                 return result;
               }
            };
         }
      });
   });

   it('Lets see whether u are teen or not', function() {
      var myAge = 14;
      expect(myAge).validateAge();
   });

   it('Lets see whether u are teen or not ', function() {
      var yourAge = 18;
      expect(yourAge).validateAge();
   });
});

上記のコードは、出力として次のスクリーンショットを生成します。

スキップスイート

メッセージバーで確認できるように、保留状態の2つの仕様ブロックが表示されます。つまり、これらの2つの仕様ブロックは*“ x” *文字を使用して無効になっています。 次の章では、さまざまな種類のジャスミンテストシナリオについて説明します。