【发布时间】:2014-05-21 07:01:35
【问题描述】:
这是带有 angular-rails gem 和 jasmine gem 的 Rails 4.0 应用程序。我也使用 angularjs-rails-resource。
我有简单的控制器:
app.controller('new', function ($scope, Appointment, flash) {
$scope.appointment = new Appointment();
$scope.attachments = [];
$scope.appointment.agendas_attributes = [];
$scope.createAppointment = function(){
$scope.appointment.attachments = $scope.attachments;
$scope.appointment.create().then(function(data){
flash(data.message);
}, function(error){
flash('error', error.data.message);
$scope.appointment.$errors = error.data.errors;
});
};
在 Jasmine 的单元测试中,我想用 jasmine.createSpyObj 隔离依赖关系:
describe("Appointment new controller",function() {
var $scope, controller, mockAppointment, mockFlash, newCtrl;
beforeEach(function() {
module("appointments");
inject(function(_$rootScope_, $controller) {
$scope = _$rootScope_.$new();
$controller("new", {
$scope: $scope,
Appointment: jasmine.createSpyObj("Appointment", ["create"])
});
});
});
});
但我得到一个错误:
TypeError: object is not a function
上线:
Appointment: jasmine.createSpyObj("Appointment", ["create"])
有人可以帮忙吗? :-)
【问题讨论】:
标签: javascript angularjs unit-testing mocking jasmine