Search code examples
node.jsmocha.jsassertchai

Mocha Chai assert looks like ignored


I have this little code:

var expect = require('chai').expect;
describe('simple check', function() {
  it('this one shows output', function() {
    expect(1).to.equal(1);
  });
});


var assert = require('chai').assert;
assert(1 === 1, 'this one looks like ignored');

and so I get

$ mocha test

simple check ✓ this one shows output

1 passing (5ms)

Why the second test is ignored?


Solution

  • Mocha does not show which assertions have been run, it just shows which tests have been run. In this case you have only one test which is this one shows output.

    So if you don't put any assertion, it still outputs the same thing:

    describe('simple check', function() {
      it('this one shows output', function() {
      });
    });
    

    Also if there's any error in any assertion in anywhere in the file, it will show it. So if you put assert(1 === 2, 'one should be two'); it will throw an error and show it to you.