My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Best practices for organising deeply nested mocha tests?

Paul Razvan Berg's photo
Paul Razvan Berg
·Aug 11, 2019

Say you want to test the behaviour of a very complex state tree:

describe("A", function() {
  describe("A.a", function() {
    describe("A.a.0", function() {
      // and so on...
    });
    describe("A.a.1", function() {
      // and so on...
    });
  });

  describe("A.b", function() {
    // and so on...
  });
});

describe("B", function() {
  // and so on...
});

How do you organise these blocks? Do you first exclude the failing states (i.e. supplying 0 to a division goes in the "B" block)? Or do you group them by role and only then process every failing input?

(I guess it'd worth it to mention that I'm particularly interested in tests written for ethereum smart contracts)