1

I can't get Lettuce / Splinter or JsTestDriver to run tests of user interaction with Backbone-generated DOM objects. For example, at the hello backbone tutorial, I want to simulate the user's click on the button labeled "Add list item", then verify that a <li> element of text "hello world1" has appeared.

JsTestDriver: I can get a reference to the button element and call click() on it, but then document.getElementsByTagName("li") fail (or return null?).

Johansen's excellent book says that testing event handlers isn't properly a unit testing task. So I tried my BDD (?) tools for Django:

Lettuce / Splinter / Django: The Splinter Browswer object can't see the text in the button, never mind get a reference to it or click it. (It does handle these operations for elements created via HTML.) Neither world.browser.is_text_present() nor find_by_id() work; passing a wait time to the former didn't help.

I would really prefer to avoid going straight to Selenium, and thought that these tools made that unnecessary. So now what?

chernevik
  • 3,922
  • 9
  • 41
  • 55

1 Answers1

1

While firing DOM events may technically not be "unit testing", it doesn't mean you can't use a unit testing framework to do it :) This is more of a case of definition.

Anyway, you can achieve what you want with e.g. JsTestDriver, but I would advise against doing it manually through e.g. click() (which likely does not do what you expect it to). I usually use jQuery to fire events, and this can safely be done with e.g. JsTestDriver. This should work even if you don't use jQuery in your production code.

Christian Johansen
  • 1,861
  • 1
  • 16
  • 22
  • Thx, but I don't entirely follow. Are you suggesting that I get a reference to the target element with jQuery, then call click() on that? Or that I make some more involved usage of the jQuery Event model to call the event? I'll have to brush up on jQuery for the latter. And yes, click() isn't behaving as I would expect. – chernevik Oct 31 '11 at 18:36
  • Are you think of the jquery.simulate.js library, w/jQuery and QUnit? Because I did get that to work. – chernevik Nov 01 '11 at 20:48