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

前端之家收集整理的这篇文章主要介绍了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();
  });
});
原文链接:https://www.f2er.com/angularjs/141163.html

猜你在找的Angularjs相关文章