加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 08:47:47 所属栏目:安全 来源:网络整理
导读:我有这个简单的测试: describe('My Controller',function() { beforeEach(function() { module('myApp'); return inject(function($injector) { var $controller = $injector.get('$controller'); this.rootScope = $injector.get('$rootScope'); this.scop
我有这个简单的测试:
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();
  });
});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读