views:

453

answers:

5

Hello,

We have a Ruby on Rails app that uses some javascript in the views. Since we have good test coverage on the rest of the app, we want to continue that here. The js we use manipulates the DOM to show/hide divs and perform incremental searching for a combobox selecting from a table.

Does anyone know of ways to test DOM manipulation?

Frank

A: 

jQuery library ships with a pretty good unit testing library you can use to test dom manipulation. The library's called QUnit.

Brian C
+1  A: 

You could use YUI Test or Selenium.

Kristof Neirynck
A: 

In the past I've done this with jsUnit.

Jeffrey Fredrick
+3  A: 

You can use the java libraries HttpUnit or HtmlUnit that can test the finished DOM after being manipulated by JS.

http://htmlunit.sourceforge.net/javascript-howto.html http://httpunit.sourceforge.net/doc/cookbook.html

Both use the full-featured JavaScript engine Mozilla Rhino, and then add their own DOM implementations.

This will allow you to run these test automatically in the background without any browser or sideeffects.

Bonus: You can use call these libraries directly from Ruby using JRuby.

morganchristiansson
A: 

I just answered a similar question. In short: take a look at Dojo's DOH, doh.robot and dijit.robotx (using Dojo is not required for DOH, and it doesn't depend on Dojo).

Eugene Lazutkin