JasmineJS-ブロックをスキップ

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

次の例では、特定のスキップ方法を学習します Spec または Suite を使用して “x” キャラクター。

仕様をスキップ

前の例を使用して変更します “x” 直前 it ステートメント。

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 ブロックは disabled 一時的に使用 “xit”

スイートをスキップ

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

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”キャラクター。次の章では、さまざまなタイプのジャスミンテストシナリオについて説明します。