10

I read the book Web Development with Node.js and Express. And there is used the function suite().

var assert = require('chai').assert;
suite('tests', function () {
  // set of tests
});

I don't understand where it comes from. I can't find any documentation about this function. Seems that it looks and has same functionality like the describe() function in Mocha.

JRI
  • 1,766
  • 13
  • 25
Andr1i
  • 319
  • 4
  • 14

2 Answers2

19

Mocha supports several different ways of writing tests (interfaces) so that you can choose a style that suits your methodology. describe() and suite() essentially do the same thing: they let you label and group together a set of tests; the grouped tests are organised under a common label in the output and can use common setup and teardown functions.

The choice of which function to use depends on whether you are using a Behaviour Driven Development (BDD) methodology (where you describe() the behaviour you want it() to do), or Test Driven Development (TDD), where you define a suite() of test()s you want your code to pass. You should choose whichever style you feel makes your code more readable.

Here's a blog explaining the Difference Between TDD and BDD with regard to test design.

JRI
  • 1,766
  • 13
  • 25
3

Documentation can be found on the mocha website: https://mochajs.org/#tdd

suite is the TDD version of describe. You generally use it to describe and isolate the functionality/features/behaviour that you are going to test.

Fiddles
  • 2,790
  • 1
  • 32
  • 35