Issue with angular.mock.inject method

前端 未结 2 2060
盖世英雄少女心
盖世英雄少女心 2021-01-07 11:01

I am using folloing jasmine test case

\'use strict\';

describe(\'companyService\', function() {

    var $httpBackend, companyService;

    beforeEach(angu         


        
2条回答
  •  北海茫月
    2021-01-07 11:27

    I found out the solution for this problem. Turns out i have missed some dependencies in the karma.conf.js . When you missed dependencies , the $inject method does not get executed . What i did was , from the index.html , copied all the dependencies (from bower componants folder and node_modules folder) and put them in the karma.conf.js under files .

    for example , i have copied all the file dependencies from index.html and put it under files

                'bower_components/angular/angular.js',
                'node_modules/angular-mocks/angular-mocks.js',
    
                'bower_components/jquery/dist/jquery.js',
                'bower_components/pnotify/pnotify.core.js',
                'bower_components/pnotify/pnotify.buttons.js',
                'bower_components/pnotify/pnotify.confirm.js',
                'bower_components/pnotify/pnotify.desktop.js',
                'bower_components/pnotify/pnotify.nonblock.js',
                'bower_components/pnotify/pnotify.callbacks.js',
                'bower_components/pnotify/pnotify.history.js',
                'bower_components/pnotify/pnotify.reference.js',
    
                'bower_components/jquery-ui/jquery-ui.min.js',
                'bower_components/bootstrap/dist/js/bootstrap.js',
    
                'js/fullcalendar.min.js',
                'js/daterangepicker.min.js',
    
                'bower_components/moment/moment.js',
                'bower_components/moment-timezone/builds/moment-timezone-with-data-2010-2020.js',
    
                'bower_components/angular-i18n/angular-locale_no.js',
                'bower_components/ng-file-upload/angular-file-upload.js',
    
                'bower_components/angular-ui-router/release/angular-ui-router.js',
                'bower_components/angular-bootstrap/ui-bootstrap-tpls.js',
    
                'bower_components/angular-translate/angular-translate.js',
                'bower_components/angular-translate-loader-static-files/angular-translate-loader-static-files.js',
    
                'bower_components/angular-pnotify/src/angular-pnotify.js',
    
                'bower_components/angular-local-storage/angular-local-storage.js',
    
                'bower_components/angular-loading-bar/build/loading-bar.min.js',
    
                'bower_components/angular-moment/angular-moment.js',
    
                'bower_components/angular-bootstrap-switch/dist/angular-bootstrap-switch.js',
                'bower_components/bootstrap-switch/dist/js/bootstrap-switch.js',
    
                'app/app.js',
                'app/**/*.js',
                'test/**/*Spec.js'
    

提交回复
热议问题