मैं बैकबोन व्यू के लिए एक परीक्षण लिख रहा हूं ताकि परीक्षण किया जा सके कि मॉडल लाने के बाद रेंडर फ़ंक्शन को बुलाया जा रहा है। परीक्षा है:Backbone.js ब्राउज़र में साइनऑन जासूसों का उपयोग करके परीक्षण देखें
beforeEach(function() {
$('body').append('<div class="sidebar"></div>');
profileView = new ProfileView();
});
it('should call the render function after the model has been fetched', function (done) {
profileView.model = new UserModel({md5: 'd7263f0d14d66c349016c5eabd4d2b8c'});
var spy = sinon.spy(profileView, 'render');
profileView.model.fetch({
success: function() {
sinon.assert.called(spy);
done();
}
});
});
मैं profileView दृश्य वस्तु के समारोह प्रस्तुत करने के लिए एक जासूस वस्तु संलग्न करने के लिए सिनोन जासूसों का उपयोग कर रहा हूँ।
दृश्य है:
var ProfileView = Backbone.View.extend({
el: '.sidebar'
, template: Hogan.compile(ProfileTemplate)
, model: new UserModel()
, initialize: function() {
this.model.bind('change', this.render, this);
this.model.fetch();
}
, render: function() {
$(this.el).html(this.template.render());
console.log("Profile Rendered");
return this;
}
});
लाने की परीक्षा में कहा जाता है के बाद, परिवर्तन घटना फायरिंग कर रहा है और देखने के प्रस्तुत करना समारोह बुलाया जा रहा है, लेकिन सिनोन जासूस का पता लगाने नहीं है कि प्रस्तुत करना है किया जा रहा है बुलाया और विफल रहता है।
एक प्रयोग के रूप में, मैं परीक्षा में समारोह प्रस्तुत करना बुला देखने के लिए अगर जासूस यह पहचान करने की कोशिश की:
it('should call the render function after the model has been fetched', function (done) {
profileView.model = new UserModel({md5: 'd7263f0d14d66c349016c5eabd4d2b8c'});
var spy = sinon.spy(profileView, 'render');
profileView.render();
profileView.model.fetch({
success: function() {
sinon.assert.called(spy);
done();
}
});
});
जासूस का पता चला बुलाया उपरोक्त मामले में किया गया था।
क्या किसी को पता है कि जासूस मेरे प्रारंभिक परीक्षण में रेंडर कॉल की पहचान क्यों नहीं कर रहा है?