it()之间有联系好不好?

Is it good or not have connection between it()?

我在 project.When 中使用 mocha 作为测试框架 我编写单元测试,我更喜欢:

describe('cooperation', () => {
  describe('create cooperation', done => {
    it('should create a cooperation between A and B', done => {
      //make a post request to create a cooperation between A and B
      //res.body.should.deepEqual({/*cooperation object*/})
      done();
    });
  });

  describe('get cooperation', done => {
    before(done => {
      //clear any cooperation in database
      //initital cooperation between A and B by fixture tool
      done();
    });

    it('get A's partner', done => {
      //make a get request to get cooperation of A
      //res.body should have B
    });
  });
});

但我的同事更喜欢:

describe('cooperation', () => {
  it('should create a cooperation between A and b', done => {
    //make a post request to create a cooperation between A and B
    //res.body.should.deepEqual({/*cooperation object*/})
    done();
  });

  it('get A's partner', done => {
    //make a get request to get cooperation of A
    //res.body should have B
  });
});

我想知道哪个更好,为什么?

我会和你的队友一起去。在我看来,你的风格有不必要的膨胀,与另一种相比可读性更差。我认为您应该问问自己,通过您的方法,您期望取得比另一个更好的成就是什么?

让您的测试简单明了。