angularjs – 为什么我的业力考验不起作用?

我有这个简单的测试:
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();
  });
});

相关文章

ANGULAR.JS:NG-SELECTANDNG-OPTIONSPS:其实看英文文档比看中...
AngularJS中使用Chart.js制折线图与饼图实例  Chart.js 是...
IE浏览器兼容性后续前言 继续尝试解决IE浏览器兼容性问题,...
Angular实现下拉菜单多选写这篇文章时,引用文章地址如下:h...
在AngularJS应用中集成科大讯飞语音输入功能前言 根据项目...
Angular数据更新不及时问题探讨前言 在修复控制角标正确变...