Uncaught ReferenceError: angular is not defined

13,970 views
Skip to first unread message

shotleybuilder

unread,
Jan 5, 2013, 2:56:38 PM1/5/13
to ang...@googlegroups.com
Hi,

This error when running Testacular is confusing me.  Anyone got any pointers?

Here is a debug log of what's happening (I've hidden directory paths).  Everything looks OK, but then ... error ;-(

Many thanks

Jason

info: Testacular server started at http://localhost:8080/
info (launcher): Starting browser Chrome
debug (launcher): Creating temp dir at /tmp/testacular-90686789
debug (launcher): google-chrome --user-data-dir=/tmp/testacular-90686789 --no-default-browser-check --no-first-run --disable-default-apps http://localhost:8080/?id=90686789
info (launcher): Starting browser Firefox
debug (launcher): Creating temp dir at /tmp/testacular-64169966
debug (watcher): Resolved files:
    /usr/lib/node_modules/testacular/adapter/lib/jasmine.js
    /usr/lib/node_modules/testacular/adapter/jasmine.js
    /home/jason/../test/unit/controllersSpec.js
    /home/jason/../test/unit/directivesSpec.js
    /home/jason/../test/unit/servicesSpec.js
    /home/jason/../public/js/app.js
    /home/jason/../public/js/controllers.js
    /home/jason/../public/js/directives.js
    /home/jason/../public/js/filters.js
    /home/jason/../public/js/services.js
debug (watcher): Watching "/usr/lib/node_modules/testacular/adapter/lib/jasmine.js"
debug (watcher): Watching "/usr/lib/node_modules/testacular/adapter/jasmine.js"
debug (watcher): Watching "/home/jason/../test/unit"
debug (watcher): Watching "/home/jason/../public/js/app.js"
debug (watcher): Watching "/home/jason/../public/js/controllers.js"
debug (watcher): Watching "/home/jason/../public/js/directives.js"
debug (watcher): Watching "/home/jason/../public/js/filters.js"
debug (watcher): Watching "/home/jason/../public/js/services.js"
debug (watcher): Add file "/usr/lib/node_modules/testacular/adapter/jasmine.js" ignored. Already in the list.
debug (watcher): Add file "/usr/lib/node_modules/testacular/adapter/lib/jasmine.js" ignored. Already in the list.
debug (watcher): Add file "/home/jason/../public/js/app.js" ignored. Already in the list.
debug (watcher): Add file "/home/jason/../public/js/controllers.js" ignored. Already in the list.
debug (watcher): Add file "/home/jason/../public/js/directives.js" ignored. Already in the list.
debug (watcher): Add file "/home/jason/../public/js/filters.js" ignored. Already in the list.
debug (watcher): Add file "/home/jason/../public/js/services.js" ignored. Already in the list.
debug (watcher): Add file "/home/jason/../test/unit/controllersSpec.js" ignored. Already in the list.
debug (watcher): Add file "/home/jason/../test/unit/directivesSpec.js" ignored. Already in the list.
debug (watcher): Add file "/home/jason/../test/unit/filtersSpec.js" ignored. Already in the list.
debug (watcher): Add file "/home/jason/../test/unit/servicesSpec.js" ignored. Already in the list.
debug (launcher): firefox http://localhost:8080/?id=64169966 -profile /tmp/testacular-64169966 -no-remote
debug (web server): serving: /usr/lib/node_modules/testacular/static/client.html
debug (web server): serving: /usr/lib/node_modules/testacular/static/testacular.js
debug: New browser has connected on socket c4xLmxv1LkBWmvpAOjsK
info (Chrome 23.0): Connected on socket id c4xLmxv1LkBWmvpAOjsK
debug (web server): serving: /usr/lib/node_modules/testacular/static/client.html
warn (launcher): Firefox have not captured in 5000 ms, killing.
debug (launcher): Cleaning temp dir /tmp/testacular-64169966
info (launcher): Trying to start Firefox again.
debug (launcher): Creating temp dir at /tmp/testacular-64169966
debug (launcher): firefox http://localhost:8080/?id=64169966 -profile /tmp/testacular-64169966 -no-remote
debug (web server): serving: /usr/lib/node_modules/testacular/static/client.html
debug (web server): serving: /usr/lib/node_modules/testacular/static/testacular.js
debug: New browser has connected on socket DA6n2jgU9IpzlZbgOjsL
info (Firefox 17.0): Connected on socket id DA6n2jgU9IpzlZbgOjsL
debug: All browsers are ready, executing
debug (web server): serving: /usr/lib/node_modules/testacular/static/context.html
debug (web server): serving: /usr/lib/node_modules/testacular/static/context.html
debug (web server): serving: /usr/lib/node_modules/testacular/adapter/lib/jasmine.js
debug (web server): serving: /usr/lib/node_modules/testacular/adapter/jasmine.js
debug (web server): serving: /home/jason/../test/unit/directivesSpec.js
debug (web server): serving: /home/jason/../test/unit/controllersSpec.js
debug (web server): serving: /home/jason/../test/unit/filtersSpec.js
debug (web server): serving: /home/jason/../test/unit/servicesSpec.js
debug (web server): serving: /home/jason/../public/js/app.js
debug (web server): serving: /home/jason/../public/js/services.js
debug (web server): serving: /home/jason/../public/js/filters.js
debug (web server): serving: /home/jason/../public/js/directives.js
debug (web server): serving: /home/jason/../public/js/controllers.js
debug (web server): serving: /usr/lib/node_modules/testacular/adapter/lib/jasmine.js
debug (web server): serving: /usr/lib/node_modules/testacular/adapter/jasmine.js
debug (web server): serving: /home/jason/../test/unit/controllersSpec.js
Chrome 23.0 ERROR
    Uncaught ReferenceError: angular is not defined
    at /home/jason/../public/js/app.js:5
Chrome 23.0: Executed 0 of 0 ERROR (0.061 secs / 0 secs)
Firefox 17.0: Executed 0 of 0
debug (web server): serving: /home/jason/../test/unit/directivesSpec.js
debug (web server): serving: /home/jason/../public/js/controllers.js
debug (web server): serving: /home/jason/../public/js/app.js
debug (web server): serving: /home/jason/../test/unit/servicesSpec.js
debug (web server): serving: /home/jason/../test/unit/filtersSpec.js
debug (web server): serving: /home/jason/../public/js/directives.js
Firefox 17.0 ERROR
    ReferenceError: angular is not defined
    at /home/jason/../public/js/app.js:5
Chrome 23.0: Executed 0 of 0 ERROR (0.061 secs / 0 secs)
Firefox 17.0: Executed 0 of 0 ERROR (0.116 secs / 0 secs)

Peter Bacon Darwin

unread,
Jan 6, 2013, 12:58:37 AM1/6/13
to ang...@googlegroups.com

Need to see what is in your test config file...

... sent from my tablet

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
 
 

shotleybuilder

unread,
Jan 6, 2013, 6:11:21 AM1/6/13
to ang...@googlegroups.com
Peter
Pretty much the default config ... no doubt there is something trivial I've messed up.
I'll take a closer look at the config, thanks for the pointer.
Thanks
Jason

// Testacular configuration
// Generated on Mon Dec 31 2012 18:52:32 GMT+0000 (GMT)


// base path, that will be used to resolve files and exclude
basePath = '../';


// list of files / patterns to load in the browser
files = [
  JASMINE,
  JASMINE_ADAPTER,
  'test/unit/*.js',
  'public/js/app.js',
  'public/js/controllers.js',
  'public/js/directives.js',
  'public/js/filters.js',
  'public/js/services.js'
  //'public/js/lib/angular/**/*.js'
];


// list of files to exclude
exclude = [
 
];


// test results reporter to use
// possible values: 'dots', 'progress', 'junit'
reporters = ['progress'];


// web server port
port = 8080;


// cli runner port
runnerPort = 9100;


// enable / disable colors in the output (reporters and logs)
colors = true;


// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel = LOG_DEBUG;


// enable / disable watching file and executing tests whenever any file changes
autoWatch = true;


// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers = ['Chrome', 'Firefox'];


// If browser does not capture in given timeout [ms], kill it
captureTimeout = 5000;


// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun = false;

Peter Bacon Darwin

unread,
Jan 6, 2013, 6:13:04 AM1/6/13
to ang...@googlegroups.com

You appear to have commented out the angulajs library

Pete
...from my mobile.

shotleybuilder

unread,
Jan 6, 2013, 12:20:33 PM1/6/13
to ang...@googlegroups.com
Peter
Yes, I'd been getting the error before commenting out.
Anyway, I've fixed it, I think, but it was rather curious.

This is what worked:

files = [
  JASMINE,
  JASMINE_ADAPTER,
  'public/js/lib/angular/1.0.3/angular.js',
  'public/js/lib/angular/1.0.3/angular-resource.js',
  'test/unit/*.js',
  //'test/lib/angular/angular-mocks.js',

  'public/js/app.js',
  'public/js/controllers.js',
  'public/js/directives.js',
  'public/js/filters.js',
  'public/js/services.js'
];

Seemingly there are problems with use of *.  These both error for me:

 'public/js/lib/angular/*/*.js' &  'public/js/lib/angular/**/*.js'

Also, it appears that the order in the array also makes a difference.  The calls to 'public/js/lib/angular/1.0.3/angular.js', &
  'public/js/lib/angular/1.0.3/angular-resource.js' have to go first ;-)

Many thanks for pointing me in the right direction.  Hopefully, this will be helpful to others who follow.

Jason

Peter Bacon Darwin

unread,
Jan 6, 2013, 12:37:15 PM1/6/13
to ang...@googlegroups.com
The wildcard versions should work fine - they do in our app: https://github.com/angular-app/angular-app/blob/master/client/test/config/unit.js
I suspect that it was just that your application was being loaded before AngularJS, hence the lack of the angular global object.
Pete

Pawel Kozlowski

unread,
Jan 6, 2013, 12:40:00 PM1/6/13
to ang...@googlegroups.com
Hi!

On Sun, Jan 6, 2013 at 6:20 PM, shotleybuilder
<drjason...@gmail.com> wrote:
> Seemingly there are problems with use of *. These both error for me:
>
> 'public/js/lib/angular/*/*.js' & 'public/js/lib/angular/**/*.js'

The problem might be in usage of starts to denote folders and
sub-folders. I don't know the exact structure of your application but
if you want to match a hierarchy of folders you need to use double
stars (**) is I'm not mistaken. As Peter have said this works on our
end without issues (even on Win).

Cheers,
Pawel

--
Question? Send a fiddle
(http://jsfiddle.net/pkozlowski_opensource/Q2NpJ/) or a plunk
(http://plnkr.co/)
Need help with jsFiddle? Check this:
http://pkozlowskios.wordpress.com/2012/08/12/using-jsfiddle-with-angularjs/

Looking for UI widget library for AngularJS? Here you go:
http://angular-ui.github.com/

shotleybuilder

unread,
Jan 6, 2013, 2:18:44 PM1/6/13
to ang...@googlegroups.com
Hi

Appears to be about ensuring angular.js gets treated before angular-resource.js.  Using wildcard * on the file name gives me an error, but Ok in the path.
These work:

 'public/js/lib/angular/1.0.3/angular.js',
 'public/js/lib/angular/1.0.3/angular-resource.js',

 'public/js/lib/angular/*/angular.js',
 'public/js/lib/angular/*/angular-resource.js',

These configs give the same error (well for me anyway ;-):

 'public/js/lib/angular/1.0.3/angular-resource.js',
 'public/js/lib/angular/1.0.3/angular.js',

 'public/js/lib/angular/1.0.3/*.js',

 'public/js/lib/angular/1.0.3/**.js',

Also, for anyone picking-up this thread, I've also had to include reference to angular-mocks.js [test/lib/angular/angular-mocks.js] to solve another error.

Thanks for all the feedback.

Jason
Reply all
Reply to author
Forward
0 new messages