Erik
Erik

Reputation: 3198

Testing Ionic with Jasmine and Karma - Uncaught ReferenceError: angular is not defined

Long story short, when I run karma.conf.js I see Uncaught ReferenceError: angular is not defined

I am starting to work with a pre-existing Ionic project.. and add some unit tests. Do I need to check our www/index.html .. I do not see angular.js included strangely enough.. is this the reason?

This team uses maven to build so I'm worried we're out of step with the rest of the community as far as building goes.

Update 1: adding <script type="text/javascript" src="lib/js/angular/angular.js"></script> at the top of www/index.html's includes has no effect.

Update 2: index.html contains ionic bundle <script src="lib/js/ionic.bundle.js"></script>

Karma.conf.js

// list of files / patterns to load in the browser
files: [
    'www/lib/js/angular/angular.js',
    'www/lib/js/angular/angular-animate.js',
    'www/lib/js/angular/angular-animate.js',
    'www/lib/js/angular/angular-mocks.js',
    'www/lib/js/angular/angular-resource.js',
    'www/lib/js/angular/angular-sanitize.js',
    'www/lib/js/angular-ui/angular-ui-router.js',
    'www/lib/js/ionic.js',
    'www/lib/js/ionic-angular.js',
    'www/js/**/*.js',
    'www/test/jasmine/*.js'
],

Upvotes: 3

Views: 2988

Answers (1)

Non
Non

Reputation: 8589

Ionic has Angular already, so you don't need to add Angular externally. You should probably remove <script type="text/javascript" src="lib/js/angular/angular.js"></script>

and make sure you are adding Ionic in your dependencies

angular.module('myApp', ['ionic'])

And: remember to do this in your index.html

<body ng-app="myApp"></body>

*Could be in body tag or html tag, just make sure you are adding it.

EDIT

as @PSL says: Ionic Bundle has Angular in it. So I guess, you should to start using Ionic Bundle and stop worrying about it.

In case you are not using Ionic Bundle, add the reference for Angular in your Index, and make the declarations I mentioned above.

your karma file should look like this

// list of files / patterns to load in the browser
    files: [
    //Angular source
    'lib/ionic/js/ionic.bundle.js',
    'lib/angular-mocks/angular-mocks.js',
    'lib/angular-local-storage/dist/angular-local-storage.js',
    'lib/ngCordova/dist/ng-cordova.js',
    'lib/ionic/js/angular-ui/angular-ui-router.js',
    'lib/angular-animate/angular-animate.js',
    'lib/angular-sanitize/angular-sanitize.js',

    //App code
    'js/*.js',
    'js/controllers/*.js',
    'js/services/*.js',

    //Test files
    'test/controllers/*.js'
    ],

in case that you are not using some of the files above, just remove it from the array files: []

Upvotes: 4

Related Questions