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?

1
  • Are you still looking for an answer? I don't want to revive a zombie. Commented Dec 27, 2011 at 3:07

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
Are you think of the jquery.simulate.js library, w/jQuery and QUnit? Because I did get that to work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.