Issue with angular.mock.inject method

微笑、不失礼 提交于 2019-12-01 02:03:48

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.

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'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!