2017-08-10 7 views
2

私は1つのアプリページのすべてのテストケースについて説明しています。私は、すべての肯定的なテストケースを含むコンテキストを持っており、その中にはすべての否定的なテストケースを含むコンテキストがあります。すべてのテストケースの前に、その前にログインが含まれています。私は否定的なテストケースのために前もって別のものを追加できることを知りたい。モカを使用して説明する前に2つを持つことはできますか?

例:

describe('X page', function(){ 
    context('As a user', function(){ 
    before(function(){ 
     login goes here 
    }); 
    it('Test case 1', function(){ 
     test case implementation goes here 
    }); 
    it('Test case 2', function(){ 
     test case implementation goes here 
    }); 
    context('Negative tests', function(){ 
     before(function(){ 
     negative tests precondition goes here 
     }); 
     it('Test case 1', function(){ 
     test case implementation goes here 
     }); 
     it('Test case 2', function(){ 
     test case implementation goes here 
     }); 
    }); 
    }); 
}); 

は、第2の前にそこに行くことはできますか?

答えて

2

はい、できます。外側describebeforeフックは、内側describeのフックの前に実行されます。 describeと同じコールバックに複数のbeforeフックがある場合は、表示された順に実行されます。 (describecontextの同義語です:Mochaは両方に同じ機能を割り当てます)

関連する問題