如何创建模拟表单数据以在Javascript控制器上执行单元测试
我有一个控制器,它执行如下功能:如何创建模拟表单数据以在Javascript控制器上执行单元测试,javascript,angularjs,unit-testing,Javascript,Angularjs,Unit Testing,我有一个控制器,它执行如下功能: angular.module('events').controller('EventsController', ['$scope', '$stateParams', '$location', 'Authentication', 'Events', function($scope, $stateParams, $location, Authentication, Events) { //initialize some stuff $scope.create
angular.module('events').controller('EventsController', ['$scope', '$stateParams', '$location', 'Authentication', 'Events',
function($scope, $stateParams, $location, Authentication, Events) {
//initialize some stuff
$scope.create = function() {
// Create new Event object
var event = new Events ({
name: this.name,
details: this.details,
date: this.date,
time: this.time,
pointValue: this.pointValue,
studentIDs: this.studentIDs
});
// Redirect after save
event.$save(function(response) {
$location.path('events/' + response._id);
// Clear form fields
$scope.name = '';
$scope.details = '';
}, function(errorResponse) {
$scope.error = errorResponse.data.message;
});
};
//rest of the controllers functions go below
};
我正在为这个控制器编写单元测试,但是,我不知道如何将示例事件注入这个函数,或者在测试中比较函数的输出。我对Javascript非常陌生,希望能得到所有帮助