jeudi 25 juin 2015

Service is undefined, angularJs unit Testing error

I have this error shown, i tried many solution at the net, like this example in http://ift.tt/1nk1wss, but it 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" is 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 + '!!!'
    }
};
});

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

<script src="http://ift.tt/1NgogVP"></script>

so i thougth its the error, but nothing.Thanks for any help.

Aucun commentaire:

Enregistrer un commentaire