3

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

6 Answers6

3

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.

Morgan Christiansson
  • 29,280
  • 1
  • 19
  • 13
2

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

Brian C
  • 201
  • 1
  • 3
1

You could use YUI Test or Selenium.

Kristof Neirynck
  • 3,934
  • 1
  • 33
  • 47
0

Use capybara https://github.com/jnicklas/capybara with a JS enabled driver such as capybara-webkit or poltergeist.

Oliver Shaw
  • 5,235
  • 4
  • 26
  • 35
Morgan Christiansson
  • 29,280
  • 1
  • 19
  • 13
0

In the past I've done this with jsUnit.

Rob W
  • 341,306
  • 83
  • 791
  • 678
Jeffrey Fredrick
  • 4,493
  • 1
  • 25
  • 21
0

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).

Community
  • 1
  • 1
Eugene Lazutkin
  • 43,776
  • 8
  • 49
  • 56