0
首先,我想說我是茉莉花的新人,所以如果問題非常基本,我懇求您的理解。我寫一個測試此文件:JavaScript文件的小茉莉花測試:測試它的最佳方法
define([
'q',
'backbone',
'marionette',
'education/eet/views/destinationview',
'education/eet/views/editdestinationview',
'education/eet/models/destination',
'common/ajaxerrorhandler',
'common/alertdialog'
], function (Q, Backbone, Marionette, DestinationView, EditDestinationView, Destination, AjaxErrorHandler, AlertDialog) {
'use strict';
var ReferenceDataController = Marionette.Controller.extend({
initialize: function (options) {
this._subjectCompositeId = options.subjectCompositeId;
},
getView: function (destinationTypes, editMode) {
var self = this,
deferred = Q.defer(),
destination = new Destination();
destination.fetch({
data: {subjectCompositeId: self._subjectCompositeId}
}).done(function() {
var view;
if (editMode) {
view = new EditDestinationView({
model: destination,
'destinationTypes': destinationTypes
});
view.on('click:saveDestination', self._handleSaveDestination, view);
} else {
view = new DestinationView({
model: destination
});
}
deferred.resolve(view);
}).fail(function (jqXHR) {
deferred.reject(jqXHR);
});
return deferred.promise;
},
_handleSaveDestination: function() {
if (this.model.isValid(true)) {
this.model.save(null, {
success: function() {
Backbone.Wreqr.radio.vent.trigger('education', 'show:destination');
},
error: function (jqXHR) {
var userFriendlyErrorString = AjaxErrorHandler.buildDefaultErrorMessage(jqXHR);
return new AlertDialog(userFriendlyErrorString);
}
});
}
}
});
return ReferenceDataController;
});
的問題是,我不是很確定我如何可以訪問的變量裏面進行測試。我是一個Java測試人員,但從未測試過Javascript,即使在我編寫時也是如此,所以我非常困惑。
任何提示或代碼將被實際讚賞。
謝謝。
感謝您的幫助ZenMaster。我知道茉莉花測試的結構,但不確定要在這裏測試什麼。你會在這裏做什麼樣的測試?再次感謝 –