Back to Mocha

BDD

docs/src/content/docs/interfaces/bdd.mdx

11.7.5956 B
Original Source

The BDD interface provides describe(), context(), it(), specify(), before(), after(), beforeEach(), and afterEach().

context() is just an alias for describe(), and behaves the same way; it provides a way to keep tests easier to read and organized. Similarly, specify() is an alias for it().

js
describe("Array", function () {
  before(function () {
    // ...
  });

  describe("#indexOf()", function () {
    context("when not present", function () {
      it("should not throw an error", function () {
        (function () {
          [1, 2, 3].indexOf(4);
        }).should.not.throw();
      });
      it("should return -1", function () {
        [1, 2, 3].indexOf(4).should.equal(-1);
      });
    });

    context("when present", function () {
      it("should return the index where the element first appears in the array", function () {
        [1, 2, 3].indexOf(3).should.equal(2);
      });
    });
  });
});