bkeepers/monologue — pull request #2 by mjansen401 (2012-05-31 21:16:32+00:00)
Title: mock event example in post_status_spec

An example of testing functions in Backbone Views without a real jQuery object. Instead of creating an $el and passing it to the the view, you can do two things:

#1 - test that your events hash is constructed properly
#2 - send a mockEvent with a currentTarget attribute to the bound function that has what you need.

Actually using a jQuery object to test the clearing of the field is interesting - what I've done is set up a fixture that wraps the html I want in a

tag, then use jQuery to find that element after my code executes to assert that it is empty. I'm not sure if that is better or worse than the current setup you have.

This is pretty basic - I think the next step would be to create a spec helper function that can generate these mockEvents with targets easily so you don't have so much setup in your beforeEach.