代码之家  ›  专栏  ›  技术社区  ›  Varun Sharma

如何解决AngularJS业力测试中“无法读取属性‘替换’为空”的问题?

  •  0
  • Varun Sharma  · 技术社区  · 8 年前

    我正在使用Karma和jasmine进行UI的单元测试。我设置了所有必需的依赖项。当我开始调试时,测试用例失败了,并且

    无法读取null的属性“replace”

    在debug.js中给出警告,但我没有使用任何debug.js文件。

    屏幕截图:

    enter image description here

    包.js

    {
      "name": "test-app",
      "version": "1.0.0",
      "description": "a tool to aid",
      "main": "index.html",
      "private": true,
      "scripts": {
        "dev": "gulp dev",
        "prod": "gulp prod"
      },
      "author": "kim",
      "license": "Myange Inc.",
      "devDependencies": {
        "event-stream": "~3.3.1",
        "gulp": "^3.9.0",
        "gulp-angular-templatecache": "^1.7.0",
        "gulp-clean": "^0.3.2",
        "gulp-concat": "^2.6.0",
        "gulp-connect": "^2.2.0",
        "gulp-maven-deploy": "^1.0.1",
        "gulp-ng-annotate": "^1.0.0",
        "gulp-uglify": "^1.2.0",
        "gulp-util": "^3.0.8",
        "gulp-zip": "^4.0.0",
        "jasmine": "^3.1.0",
        "karma": "^2.0.5",
        "karma-chrome-launcher": "^2.2.0",
        "karma-jasmine": "^1.1.2",
        "karma-jasmine-html-reporter": "^1.2.0",
        "karma-ng-html2js-preprocessor": "^1.0.0",
        "lodash": "^4.0.0",
        "webdriver-manager": "10.2.5"
      },
      "dependencies": {
        "angular-mocks": "^1.7.2"
      }
    }
    

    单元测试用例.js

    describe('app.way-bus of test ', function() {
      // beforeEach(angular.mock.module('app'));
      var $controller, $rootScope;
      var DTOptionsBuilder, DTColumnDefBuilder, $http, $q, $compile, Notifier, $location, $sce, $filter, FRh, Rh, RhAuth, $stateParams, $state;
      beforeEach(angular.mock.module('restheart'));
      beforeEach(angular.mock.module('app.cargo-watchListMgmt', function($provide) {
        mockedFactory = {
          save: jasmine.createSpy()
        };
        Notifier = $provide.value('Notifier', mockedFactory);
      }));
      beforeEach(inject(function(_$controller_, _$rootScope_,_Rh_,_$stateParams_,_$state_,_Notifier_){
        // The injector unwraps the underscores (_) from around the parameter names when matching
        $controller = _$controller_;
        $rootScope = _$rootScope_;
        console.log($rootScope)
    
        Rh = _Rh_;
        //RhAuth = _RhAuth_;
        $stateParams = _$stateParams_;
        $state = _$state_;
        Notifier = _Notifier_;
      }));
    
      describe('call fetchData', function() {
        it('check', function() {
          var $scope = $rootScope.$new();
          console.log($scope)
          var controller = $controller('wayBusCntrl', {
    
            $scope: $scope,
    
            Rh: Rh,
            //RhAuth: RhAuth,
            $stateParams: $stateParams,
            $state: $state,
            Notifier: Notifier
          });
    
          expect($scope.xyz).toBe('satya')
        });
      });
    
    
    });
    

    因此,我无法处理我的单元测试,因为这个错误(无法读取属性'replace'为null)。

    0 回复  |  直到 8 年前