# JavaScript Testing?

**URL:** <https://www.ruby-forum.com/t/javascript-testing/117939>\
**Category:** Rails\
**Created:** [October 22, 2007, 5:08pm UTC](https://www.ruby-forum.com/t/javascript-testing/117939 "2007-10-22T17:08:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![plambert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9d8465/32.png) [@plambert](https://www.ruby-forum.com/u/plambert)\
**Post date:** [October 22, 2007, 5:08pm UTC](https://www.ruby-forum.com/t/javascript-testing/117939/1 "2007-10-22T17:08:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![plambert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9d8465/32.png) [@plambert](https://www.ruby-forum.com/u/plambert)\
**Post date:** [October 22, 2007, 5:24pm UTC](https://www.ruby-forum.com/t/javascript-testing/117939/2 "2007-10-22T17:24:55Z")

</div>

There are some answers to your question here. First of all, there’s  
javascript\_test, built for [script.aculo.us](http://script.aculo.us) testing, and uses their own  
testing framework:

[http://svn.rubyonrails.org/rails/plugins/javascript\_test/](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

---

<div class="post-metadata">

**Author:** ![plambert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9d8465/32.png) [@plambert](https://www.ruby-forum.com/u/plambert)\
**Post date:** [October 22, 2007, 5:44pm UTC](https://www.ruby-forum.com/t/javascript-testing/117939/3 "2007-10-22T17:44:52Z")

</div>

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.

–  
Phlip
