我在茉莉花测试中无法理解间谍。
当我运行以下测试时,我可以CLOSE EVENT
在控制台中看到输出,但测试triggers close
失败。
如何使用间谍正确编写测试?
define([
'backbone'
], function(Backbone){
describe('TEST', function(){
beforeEach(function(){
this.view = new (Backbone.View.extend({
initialize: function(){
_(this).bindAll('close');
this.$el.append($('<span>', {class: 'closeview'}));
$('body').append(this.$el);
this.$el.on('click', '.closeview', this.close);
},
close: function(){
console.log('CLOSE EVENT');
}
}));
});
it('exists', function(){
expect(this.view.$el).toBeVisible();
});
it('triggers close', function(){
spyOn(this.view, 'close');
this.view.$el.find('.closeview').trigger('click');
expect(this.view.close).toHaveBeenCalled();
});
});
});