testbox toThrow()

85 views
Skip to first unread message

Rex Chickything

unread,
Aug 22, 2018, 1:25:05 PM8/22/18
to col...@googlegroups.com
I have a Object.cfc that has a function getData():

component {
   function getData(){
      throw(message="error here", detail="details here");
   }
}

In a ObjectTest.cfc. I have:
it( "force error", function(){
   expect( obj.getData().toThrow(type="application") );
});

When I do that, I'm expecting the test to pass, since I'm telling it to expect an error.

But, it fails, and goes into the "Errors" result.

How do I get that to work?  Thanks!

- Rex

Eric Peterson

unread,
Aug 22, 2018, 1:33:40 PM8/22/18
to col...@googlegroups.com
Your `toThrow` should be called on `except`, not your function call.

expect( obj.getData() ).toThrow( type = "application" );
--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.
To post to this group, send email to col...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/coldbox/CAEW7p78D54Vaiu07yhLV%3DFoZqvQw2rDo1-u25KUFcrQ2E_ovsw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Brad Wood

unread,
Aug 22, 2018, 1:49:04 PM8/22/18
to col...@googlegroups.com
Eric is right, but there's more.  You also need to wrap your failing function in a closure:

expect( function() { obj.getData() } ).toThrow( type = "application" );  

Please read the docs :)


Thanks!

~Brad

Developer Advocate
Ortus Solutions, Corp 

ColdBox Platform: http://www.coldbox.org 



Rex Chickything

unread,
Aug 22, 2018, 4:25:31 PM8/22/18
to col...@googlegroups.com

Rex Chickything

unread,
Aug 30, 2018, 6:26:45 PM8/30/18
to col...@googlegroups.com
Thanks, that works for Lucee, but it doesn't work on ACF.

So, this same code works on Lucee 4.5.5.006 final, but not on Adobe CF 2016,0,06,308055:

describe( "CF/Lucee Test", function(){
it( "force error", function(){
expect( function(){ x = y } ).toThrow(type="expression");
});
});

It errors out with "Invalid construct: Either argument or name is missing."

If I comment out the expect line, or change it out with something like expect(true).toBeTrue() it works ok

Luis Majano

unread,
Aug 30, 2018, 6:39:46 PM8/30/18
to col...@googlegroups.com
Your pr Clem is the missing semicolon in the closure

Luis Majano
CEO
Ortus Solutions, Corp
 

From: 32041341600n behalf of
Sent: Thursday, August 30, 2018 5:26 PM
To: col...@googlegroups.com
Subject: Re: [coldbox:27135] testbox toThrow()
 

Rex Chickything

unread,
Aug 30, 2018, 7:43:04 PM8/30/18
to col...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages