Запустите хук "после" для каждого вложенного "описания" с помощью mochaJS - PullRequest
0 голосов
/ 11 июля 2019

Для каждого вложенного describe я хочу выполнить следующую последовательность:

  1. before -> создать учетную запись
  2. it -> запустить тесты
  3. 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();
    });
  });
});
...