2017-08-10 75 views
2

我有一個應用程序頁面的所有測試用例的描述。我有一個包含所有正面測試用例的上下文,然後在其中包含所有負面測試用例的上下文。在所有測試用例之前,我有一個包含登錄的測試用例。我想知道我可以添加另一個負面測試用例。我可以在裏面有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

是的,你可以。在外部describe中的before鉤子在內部describe中的鉤子之前執行。如果在與describe相同的回調中有多個before掛鉤,它們將按照它們出現的順序執行。 (請注意,describecontext的同義詞:摩卡向兩者分配相同的功能。)

相關問題