Я пытаюсь проверить, что при нажатии на элемент вызывается функция.Казалось бы, достаточно просто, но я, должно быть, упускаю что-то глупое, потому что не могу заставить этот простой пример работать.
Вот мой взгляд
(function($) {
window.LaserMonitor = {
Views: {}
};
window.LaserMonitor.Views.WorkstationSummary = Backbone.View.extend({
tagName: 'li',
className: 'StationItem',
initialize: function() {
_.bindAll(this, 'showDetails');
this.template = _.template($("#WorkstationSummary").html());
},
events: {
'click h3' : 'showDetails'
},
showDetails: function() {
},
render: function() {
var renderedTmpl = this.template(this.model.toJSON());
$(this.el).append(renderedTmpl);
return this;
}
});
})(jQuery);
, а вот мойТест Жасмин:
describe('WorkstationSummary Item', function() {
beforeEach(function() {
_.templateSettings = {
interpolate: /\{\{(.+?)\}\}/g,
evaluate: /\{\{(.+?)\}\}/g
};
loadFixtures('LaserMonitorFixture.html');
this.model = new Backbone.Model({
id: 1,
name: 'D8',
assigned: 1900,
inProgress: 4,
completed: 5
});
this.view = new window.LaserMonitor.Views.WorkstationSummary({model: this.model});
});
describe('Events', function() {
beforeEach(function() {
this.view.render();
});
it('should trigger click event', function() {
this.header = this.view.$('h3');
spyOn(this.view, 'showDetails');
this.header.click();
expect(this.view.showDetails).toHaveBeenCalled();
});
});
});
Результат этого запуска:
Ошибка: ожидается вызов шпиона на showDetails.в новом (http://localhost:57708/JobMgr2/test-js/lib/jasmine-1.0.2/jasmine.js:102:32) в [объектный объект] .toHaveBeenCalled (http://localhost:57708/JobMgr2/test-js/lib/jasmine-1.0.2/jasmine.js:1171:29) в [объектный объект]. (http://localhost:57708/JobMgr2/test-js/spec/LaserMonitorSpec.js:33:34) в [объектный объект] .execute (http://localhost:57708/JobMgr2/test-js/lib/jasmine-1.0.2/jasmine.js:1001:15) в [объектный объект] .next_ (http://localhost:57708/JobMgr2/test-js/lib/jasmine-1.0.2/jasmine.js:1790:31) вhttp://localhost:57708/JobMgr2/test-js/lib/jasmine-1.0.2/jasmine.js:1780:18
РЕДАКТИРОВАТЬ: Добавление шаблона приспособления для полноты:
<script type="text/template" id="WorkstationSummary">
<h3>{{ name }} ({{ assigned }}/{{ inProgress }}/{{ completed }})</h3>
<ul>
</ul>
</script>