首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我的业力测试不起作用?

为什么我的业力测试不起作用?
EN

Stack Overflow用户
提问于 2016-07-11 13:45:10
回答 1查看 104关注 0票数 7

我有一个简单的测试:

代码语言:javascript
复制
    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();
  });
});

控制器如下所示:

代码语言:javascript
复制
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;
}]);

测试一直失败,终端并没有给出任何有用的信息来解释原因。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-11 14:04:50

不要在测试中使用this,它指的是套件不同部分的不同内容。

相反,初始化describe命名空间中的作用域“容器”:

代码语言:javascript
复制
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', {
        '$scope': this.scope,
      });
    });
  });

  it('should have a controller', function() {
    expect(scope.controller).toBeDefined();
  });
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38308581

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档