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() {
myFunctionTobeChecked({}).then(
function() {throw new Error('Test failed: myFunctionTobeChecked({}) should be failed when empty Object was given');},
function(error) {assert(error, error.message);}
);
});
Written by kanshuYokoo
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#