2017-08-10 50 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的同义词:摩卡向两者分配相同的功能。)

相关问题