Back to Mocha

Require

docs-next/src/content/docs/interfaces/require.mdx

11.7.6728 B
Original Source

The require interface allows you to require the describe and friend words directly using require and call them whatever you want. This interface is also useful if you want to avoid global variables in your tests.

:::note The require interface cannot be run via the node executable, and must be run via mocha. :::

js
var testCase = require("mocha").describe;
var pre = require("mocha").before;
var assertions = require("mocha").it;
var assert = require("chai").assert;

testCase("Array", function () {
  pre(function () {
    // ...
  });

  testCase("#indexOf()", function () {
    assertions("should return -1 when not present", function () {
      assert.equal([1, 2, 3].indexOf(4), -1);
    });
  });
});