Mocha: AssertionError not caught by mocha 2.2.5

Created on 22 May 2015  Â·  3Comments  Â·  Source: mochajs/mocha

Whenever there is a failing assertion, I tried with both nodejs' native assertion and chai's, mocha will crash. The end result is I cannot run all tests, unless all tests pass, as it will crash at the first failure.

Example

var assert = require('assert')

describe('something', function() {
  assert(true == false)
}

describe('something else', function() {
  assert(true == true)
}

will output

assert.js:86
  throw new assert.AssertionError({
        ^
AssertionError: false == true
    at Suite.<anonymous> (/home/charlie/code/code-fellows/jsf2/foundations-js-lab1/test/excercise1Tests.js:12:3)
    at context.describe.context.context (/home/charlie/lib/node_modules/mocha/lib/interfaces/bdd.js:49:10)
    at Object.<anonymous> (/home/charlie/code/code-fellows/jsf2/foundations-js-lab1/test/excercise1Tests.js:10:1)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at /home/charlie/lib/node_modules/mocha/lib/mocha.js:192:27
    at Array.forEach (native)
    at Mocha.loadFiles (/home/charlie/lib/node_modules/mocha/lib/mocha.js:189:14)
    at Mocha.run (/home/charlie/lib/node_modules/mocha/lib/mocha.js:422:31)
    at Object.<anonymous> (/home/charlie/lib/node_modules/mocha/bin/_mocha:398:16)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

Most helpful comment

Hi @CADBOT!

describes are not the tests, but the suites. The tests are its:

var assert = require('assert')

describe('a suite', function () {
    it('something', function() {
        assert(true == false)
    })

    it('something else', function() {
        assert(true == true)
    })
})

output:

➜  temp  mocha


  a suite
    1) something
    ✓ something else


  1 passing (8ms)
  1 failing

  1) a suite something:

      AssertionError: false == true
      + expected - actual

      +true
      -false

      at Context.<anonymous> (test/testerino.js:5:9)


I hope this helped! Cheers!

All 3 comments

Hi @CADBOT!

describes are not the tests, but the suites. The tests are its:

var assert = require('assert')

describe('a suite', function () {
    it('something', function() {
        assert(true == false)
    })

    it('something else', function() {
        assert(true == true)
    })
})

output:

➜  temp  mocha


  a suite
    1) something
    ✓ something else


  1 passing (8ms)
  1 failing

  1) a suite something:

      AssertionError: false == true
      + expected - actual

      +true
      -false

      at Context.<anonymous> (test/testerino.js:5:9)


I hope this helped! Cheers!

@dasilvacontin Well... that was silly of me! Thanks!

No worries! You can also try asking at Gitter next time: https://gitter.im/mochajs/mocha.

Come back if you have any doubt or find an issue. :)

Was this page helpful?
0 / 5 - 0 ratings