JavaScript Testing?

My Rails application has almost as much (and maybe more) JavaScript as
it does Ruby code, and I'm wondering what the best option is for
testing it. Has any consensus developed regarding the best way of
testing JavaScript code in a Rails application? How are people
testing JavaScript in their own applications?

Thanks,
  --Paul

There are some answers to your question here. First of all, there’s javascript_test, built for script.aculo.us testing, and uses their own testing framework:

http://svn.rubyonrails.org/rails/plugins/javascript_test/

I’ve built another plugin around this concept, but using jsUnit instead and added code generators to make it easier to build up Javascript code source and test trees. I haven’t released anything yet (both me just not doing it and need to make sure I’m not breaking any licensing of the original javascript_test).

Send me an email if you want to check out what I’ve done and I’ll send you the code. One of these days I’ll clean up the plugin and release it officially.

Jason

Paul E. G. Lynch wrote:

My Rails application has almost as much (and maybe more) JavaScript as
it does Ruby code, and I'm wondering what the best option is for
testing it. Has any consensus developed regarding the best way of
testing JavaScript code in a Rails application? How are people
testing JavaScript in their own applications?

I test the JS one-liners that appear inside HTML attributes (such as
onclick) using assert_javascript.

This has the benefit of being a true unit test, without the overhead
of invoking a web browser against its optimization profiles.