对于每个嵌套的describe
,我要运行以下序列:
before
->创建帐户it
->运行测试after
->删除创建的帐户我的问题是after
挂钩仅在运行所有describe
之后运行,而不是在每个describe
上运行。
如何按上述顺序运行测试?
let res;
const randomAccount = {
'email': 'automation17@yahoo.com',
'password': '123456',
};
describe('Create accounts with email and password', function() {
describe('should create a valid account', function() {
before(function() {
return accountsHelper.createNewAccount(randomAccount)
.then(function(response) {
res = response;
});
});
it('should return status code 200', function(done) {
expect(res.status).to.equal(commonData.statusCode.ok);
done();
});
it('should return response', function(done) {
expect(res.body.admin).to.equal(false);
done();
});
after(function() {
return accountsHelper.deleteAccount();
});
});
describe('should create an invalid account', function() {
before(function() {
return accountsHelper.createNewAccount(randomAccount)
.then(function(response) {
res = response;
});
});
it('should return response', function(done) {
expect(res.body.admin).to.equal(false);
done();
});
after(function() {
return accountsHelper.deleteAccount();
});
});
});