Last Updated: March 10, 2018
· kanshuYokoo

AssertionError: Missing expected exception. node.js assertion

When I use the assert.throws of the node.js assert class with mocha to do unit test on javascript, I got the error message saying 'AssertionError: Missing expected exception'.
this is because assert.throws dose not handle Error thrown by an async function. so I have to catch the error in the test code and assert the result instead of using assert.throw.
for example,

myFunctionTobeChecked(Object) should take a valid Object as an argument.

it('myFunctionTobeChecked(Object)', function() {
        function() {throw new Error('Test failed: myFunctionTobeChecked({}) should be failed when empty Object was given');},
        function(error) {assert(error, error.message);}
Say Thanks