我有这个简单的测试:
describe('My Controller',function() { beforeEach(function() { module('myApp'); return inject(function($injector) { var $controller = $injector.get('$controller'); this.rootScope = $injector.get('$rootScope'); this.scope = this.rootScope.$new(); this.controller = $controller('MyCtrl',{ '$scope': this.scope,}); }); }); it('should have a controller',function() { expect(this.controller).tobedefined(); }); });
控制器看起来像这样:
angular.module('myApp').controller('MyCtrl',['$scope','$state','$filter','$q','BookingService','ngToast','$uibModal',function($scope,$state,$filter,$q,BookingService,ngToast,$uibModal) { $scope.bs = BookingService; $scope.roundtrip = false; $scope.reservationDetails = {}; $scope.originAddress = false; $scope.destinationAddress = false; $scope.reservationDetails.roundtrip = false; $scope.seatReservationDepart = {}; $scope.charter = false; }]);
测试保持失败,终端并没有真正提供任何有用的信息.
不要在测试中使用它,它指的是套件不同部分的不同内容.
而是在describe命名空间中初始化范围“容器”:
describe('My Controller',function() { var scope = {}; beforeEach(function() { module('myApp'); return inject(function($injector) { var $controller = $injector.get('$controller'); this.rootScope = $injector.get('$rootScope'); this.scope = this.rootScope.$new(); scope.controller = $controller('MyCtrl',function() { expect(scope.controller).tobedefined(); }); });
原文地址:https://www.jb51.cc/angularjs/141163.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。