views:

52

answers:

1

I am running Rhino and trying to determine how to do an assert_equals() or its equivalent in Javascript. From the Rhino shell I can load qunit, but I can't create an assertion that will fail.

What is the easiest way to use assertions in Javascript? I will be using Javascript in environments other than a web browser, so knowing how to do this from the Rhino shell would be very helpful.

Example of what does not work.

js> load("qunit.js")
js> equals(5,4,"message")
js> 
js> 
+3  A: 

It's fairly easy to implement your own assert() function in javascript which throws an exception when the assertion fails. The implementation documented here is fairly concise and should do the job.

Gus
Yeah. That was an efficient approach. I just needed to create a short function called assert_equal(x,y) that returned true when equal and threw an exception when not equal. Very light weight approach. Thanks
Chris