Service is undefined, angularJs unit Testing error -


i have error shown, tried many solution @ net, example in http://www.benlesh.com/2013/06/angular-js-unit-testing-services.html, seems nothing works.

*****app.js

 var app = angular.module('myapp', ['ui.router','ui.bootstrap','dialogs','ngresource']);          app.config(['$stateprovider', '$urlrouterprovider','$resourceprovider', function($stateprovider, $urlrouterprovider,$resourceprovider) {              $urlrouterprovider.otherwise('/');              $stateprovider                 .state('home', {                     url:'/',                     views: {   ......}})   }]); 

*****test.js

     describe('basicservice tests', function (){         beforeeach(module('myapp'));        var basic;         // excuted before each "it" run.        beforeeach(inject(function(basicservice) {             basic = basicservice;        }));         it('should make text exciting', function (){         //var result = basic.excitetext('bar');          expect(basic.excitetext('bar')).tobe('bar!');       }); }); 

***** service.js

angular.module('myapp').factory('basicservice', function(){ return {     excitetext: function(msg) {         return msg + '!!!'     } }; }); 

*****error

minerr/<@c:/_stage/myprojet/src/main/webapp/js/angular.js:63:12 loadmodules/<@c:/_stage/myprojet/src/main/webapp/js/angular.js:4138:15 foreach@c:/_stage/myprojet/src/main/webapp/js/angular.js:323:11 loadmodules@c:/_stage/myprojet/src/main/webapp/js/angular.js:4099:5 createinjector@c:/_stage/myprojet/src/main/webapp/js/angular.js:4025:11 workfn@c:/_stage/myprojet/src/main/webapp/js/angular-mocks.js:2425:44 createstartfn/<@c:/_stage/myprojet/src/main/webapp/js/adapter.js:317:5 typeerror: basic undefined in c:/_stage/myprojet/src/main/webapp/cportal/component/administration/cafingerprint/cafingerprintservice_test.js (line 20) @c:/_stage/myprojet/src/main/webapp/cportal/component/administration/cafingerprint/cafingerprintservice_test.js:20:9 createstartfn/<@c:/_stage/myprojet/src/main/webapp/js/adapter.js:317:5 

ps: in karma.config.js, added these files. also, tried var app = angular.module('myapp', []); because didn't include them in 'karma.config.js' , call them this,

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.js"></script> 

so thougth error, nothing.thanks help.

seems needed files not correctly set in karma.config.js. can run test when using following karma.config.js:

module.exports = function (config) {       var configuration = {         autowatch: false,          frameworks: ['jasmine'],           files: [              'lib/angular.js',             'lib/angular-resource.js',             'lib/angular-ui-router.js',             'lib/angular-mocks.js',             'app.js',             'service.js',             'test/**/*js'          ], ... 

of course, need make sure references files there , specified paths (relative karma.config) correct (in project spec files in 'test' folder, libraries - in 'lib', application files located in same directory karma configuration file)


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -