Issue with angular.mock.inject method

前端 未结 2 2061
盖世英雄少女心
盖世英雄少女心 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

    You should update the "karma-chrome-launcher" and "karma-firefox-launcher" in node_module. This may be solve the issue.

    npm install karma-chrome-launcher

    npm install karma-firefox-launcher

    If you think the issue because of "angular.mock.inject " then one can use inject function.

    But I think your unit test script is not getting chance for loading and execution.So,this will not reason for above error.

    Thanks.

    0 讨论(0)
  • 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'
    
    0 讨论(0)
提交回复
热议问题