Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't mocha have a built in assert definition

So I was trying to configure mocha as the test framework for a javascript project I am working on, and I hit upon the strange fact that you have to use a seperate assertion framework. Mocha's documentation on assertions states that it's designed to work with any assertion framework, which is a laudable goal, but why does it not provide any built in assertion methods? I just struggle to think of any use case where you would want a testing framework, but no way to pass or fail a test.

like image 412
Ceilingfish Avatar asked Dec 15 '22 08:12

Ceilingfish


1 Answers

As Jeff mentioned the designers of Mocha left their users the choice of using any assertion library at all. As to why no default assertions, because Mocha does not need it to work. Execute the following test:

var a = 1;
it("test", function () {
    if (a !== 2)
        throw new Error("a should equal 2");
});

You get the output:

  1) test

  0 passing (3ms)
  1 failing

  1)  test:
     Error: a should equal 2
     [...]

It works just fine without an assertion library.

like image 147
Louis Avatar answered Jan 07 '23 18:01

Louis