Assert isUndefined silences errors, and gives false positives
andreineculau opened this issue · 1 comments
andreineculau commented
Just tried an
assert(function_that_throws_an_error()()).isUndefined();
and it passes, since the error is absorbed.
mmonteleone commented
Hi @andreineculau. I might not be fully understanding your question. For example, the following should pass:
describe("undefined assertions", function() {
it("should correctly assert when an item is undefined", function(){
var someObject = {};
assert(someObject.function_that_throws_an_error).isUndefined();
});
it("should correctly assert when a parameter is defined", function(){
var someObject = { function_that_throws_an_error: function(){ throw 'my error' } };
assert(someObject.function_that_throws_an_error).isDefined();
});
});
And the following should allow asserting that a function throws an error.
describe("error assertions", function(){
it("should correctly assert a function throws an error", function(){
var function_that_throws_an_error = function(){
throw 'some error';
};
assert(function_that_throws_an_error).throwsException();
});
});
I've also tried your example as...
it("should not absorb errors", function(){
var function_that_throws_an_error = function(){
throw 'some error';
};
assert(function_that_throws_an_error()()).isUndefined();
});
...and the test does seem to fail for me. Am I misunderstanding?
Thanks