I’m writing unit tests on a backbone.js view and I’m trying to test whether the events are set properly. Is there a way I can do this?
I’m also using jQuery so I’ve tried $(view.el).data().events but nothing is bound there.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yep, you can use jquery to test to see if an event is wired up by looking at the events key in the data object like so:
This all will work, if and only if the view has been attached to the dom.
Hope this helps,
MatthewJ
Update: In jQuery 1.8 the API for this has changed to:
$._data(element, "events")See this issue