[testbox, in cb 3.8.1] $assert.throws()

Doing xUnit style test cases.

I was almost CERTAIN that I have this right, but clearly I do not. Or it’s broken, I’m not sure which. Testing the bolded line OUTSIDE the assert.throws() function works correctly. I would’ve expected this to say “Nope, you didn’t get that error”, since I introduced x’s into the type and regex.

$assert.throws(target=function(){ // Can't find what wasn't loaded **oModel.getCollectionData(key='void');** }, type='**x**SearchService.getCollectionData', regex='["was not found **xxxx**in keys"]');

Outside the throws() function, I get this error.

Inside the $assert.throws(), it just rolls on like the test case passed. What am I missing? Is there another way to approach this? Should I just forget about assert.throws() and just put it straight into the test case function with a try/catch of my own? The assert.throws() does “catch” the error and indicate the test case passed, but I thought this was to make sure my API gave the errors I would expect to give out, by adding those extra args.

  • WB

Also, I’m on Railo 4.x.

Perhaps more re-reading before sending is in order. By this sentence:
“Testing the bolded line OUTSIDE the assert.throws() function works correctly.”

I mean “gives the expected error and fails the test case”.

Got another similar example, this time on Coldfusion 11.
$assert.throws(target:local.oProduct.getWorkflowType(), message:‘Billing.Product.getWorkflowType() should throw an error when the ID is NOT populated.’);

This is throwing an error, right back to the testing framework, but shouldn’t the error be suppressed in favor of the $assert.throws()? I would expect the throws() to “catch” the error and the test case to pass.

target:local.oProduct.getWorkflowType() is not passing a function reference but the result of the function. I would think you want target:local.oProduct.getWorkflowType instead (without the open/close parens)

For this issue and the original post (which while test-related is a separate question), a self-contained test case that demonstrates the issue would probably be helpful.



That’s it, exactly! Drop the parens. Thanks, Brad!

That’s it, exactly! Drop the parens. Thanks, Brad!