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.
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.
Share Improve this question asked Jul 29, 2013 at 23:18 CeilingfishCeilingfish 5,4554 gold badges48 silver badges72 bronze badges3 Answers
Reset to default 9As 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.
The node standard library includes an assert module. Use another assertion library if you like; however, for many use-cases, the standard assert is enough.
Because it doesn't want to dictate what type of assertion framework you use. Some people like the QUnit assertion style while others prefer a more BDD style like Jasmine.