This was a curly one. I've been doing some testing recently, so I've been giving TestBox a bit of a thrashing. Yesterday I was a bit bemused that some of my tests were failing (that's not actually any sort of surprise given what I'm testing. Ahem), but other tests were erroring. yet they were testing much the same thing, and the condition causing the failure was the same for both the failing and erroring tests. I thought there was something weird afoot with TestBox, so I hit-up Luis about it.
I boiled the repro down to this:
// ErrorInsteadOfFail.cfc
component extends=testbox.system.basespec {
function run(){
describe("Replicating issue", function(){
it("demonstrates a baseline", function(){
expect(false).toBeTrue();
});
it("demonstrates the error", function(){
var results = [1,2,3];
results.each(function(result){
expect(false).toBeTrue();
});
});
});
}
}
This is really contrived, so don't pay too much attention to the code. Just focus on these two bits:
- calling
expect()
directly in my test; - calling
expect()
within an iteration function, within an inline function expression.
The expectation on each is the same: that false is true. Which it isn't (I'm not going too fast, right? ;-), so the test should fail.
However I get this:
Notice how the second test isn't failing, it's actually erroring.
I raised a ticket for this: TESTBOX-127.
Luis came back to me a coupla hours later with the interesting observation that it seems when an exception is thrown within a closure, then ColdFusion doesn't just let it error, it wraps it up in a different exception, and throws that.
That's a bullshit thing for ColdFusion to be doing. Lucee, btw, does not do this: it behaves properly.
I expanded my tests out to cover a couple more things: