Event issue
http://stackoverflow.com/questions/10932160/nothing-happens-when-i-trigger-event-with-backbone
by fguillen
HTML
<script src="http://documentcloud.github.com/underscore/underscore.js"></script>
<script src="http://documentcloud.github.com/backbone/backbone.js"></script>
<script src="https://raw.github.com/jeromegn/Backbone.localStorage/master/backbone.localStorage.js"></script>
<script src="http://sinonjs.org/releases/sinon-1.3.4.js"></script>
<html>
<head>
<link href="http://blog.bandzarewicz.com/stylesheets/jasmine/jasmine.css" media="screen, projection" rel="stylesheet" type="text/css">
<script src="https://raw.github.com/pivotal/jasmine/v1.1.0/lib/jasmine-core/jasmine.js"></script>
<script src="https://raw.github.com/pivotal/jasmine/v1.1.0/lib/jasmine-core/jasmine-html.js"></script>
<title>Jasmine Spec Runner</title>
</head>
<body>
<a href="#" id="addQuestion">Add question</a>
</body>
</html>
JavaScript
var AppView = Backbone.View.extend({
el: $("body"),
events: {
"click #addQuestion": "addQuestionModel"
},
addQuestionModel: function() {
alert( "I'm the event handler" );
},
});
describe("Event", function() {
beforeEach(function(){
var appView = new AppView();
});
it("click on addQuestion", function() {
$("#addQuestion").click();
});
});
//
// Jasmine spec runner
//
(function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
var trivialReporter = new jasmine.TrivialReporter();
jasmineEnv.addReporter(trivialReporter);
jasmineEnv.specFilter = function(spec) {
return trivialReporter.specFilter(spec);
};
var currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
execJasmine();
};
function execJasmine() {
jasmineEnv.execute();
trivialReporter.outerDiv.className += ' show-passed';
}
})();