Write better unit tests in JS or TS thanks to a new set of rules dedicated to Mocha and Chai

Hello JavaScript, TypeScript developers,

We believe that test code quality is as important as main code quality. This is why we just released a set of rules to help you write better tests with Mocha or Chai.

Rules dedicated to Mocha:

  • S6079: Tests should not execute any code after “done()” is called
  • S6080: Mocha timeout should be disabled by setting it to “0”

Rules dedicated to Chai:

  • S5863: Assertions should not be given twice the same argument
  • S3415: Assertion arguments should be passed in the correct order
  • S2970: Assertions should be complete
  • S6092: Chai assertions should have only one reason to succeed

Rules for Mocha and Chai:

  • S2699: Tests should include assertions
  • S5958: Tests should check which exception is thrown

These rules are available now on SonarCloud.io and are part of the recently released SonarQube 9.2.


1 Like