Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Angular fails to instantiate module ngLocale in tests after upgrade to 1.3.12 #10967

Closed
nadavsinai opened this issue Feb 4, 2015 · 14 comments · Fixed by #10969
Closed

Angular fails to instantiate module ngLocale in tests after upgrade to 1.3.12 #10967

nadavsinai opened this issue Feb 4, 2015 · 14 comments · Fixed by #10969

Comments

@nadavsinai
Copy link

In our CI the tests failed, I tried to reproduce locally and could not until I removed our bower libs and reinstalled. (we were asking for ~1.3).
I played with bower.json angular versions and found that 1.3.11 works and 1.3.12 fails.

the code that breaks our app is found in commit 6ec5946

line 2138 in angular-mocks.js

 Error: [$injector:modulerr] Failed to instantiate module ng due to:
  Error: [$injector:modulerr] Failed to instantiate module ngLocale due to:
  TypeError: 'undefined' is not an object (evaluating 'annotatedFunctions.push')
  at /Volumes/OSxData/websites/startapp/portal/public/lib/angular-mocks/angular-mocks.js:2145
  at invoke (/Volumes/OSxData/websites/startapp/portal/public/lib/angular/angular.js:4163)
  at instantiate (/Volumes/OSxData/websites/startapp/portal/public/lib/angular/angular.js:4193)
  at provider (/Volumes/OSxData/websites/startapp/portal/public/lib/angular/angular.js:4028)
  at /Volumes/OSxData/websites/startapp/portal/public/lib/angular/angular.js:4020
  at runInvokeQueue (/Volumes/OSxData/websites/startapp/portal/public/lib/angular/angular.js:4091)
  at /Volumes/OSxData/websites/startapp/portal/public/lib/angular/angular.js:4099
  at forEach (/Volumes/OSxData/websites/startapp/portal/public/lib/angular/angular.js:323)
  at loadModules (/Volumes/OSxData/websites/startapp/portal/public/lib/angular/angular.js:4123)
  at /Volumes/OSxData/websites/startapp/portal/public/lib/angular/angular.js:4098
  at forEach (/Volumes/OSxData/websites/startapp/portal/public/lib/angular/angular.js:323)
  at loadModules (/Volumes/OSxData/websites/startapp/portal/public/lib/angular/angular.js:4123)
  at createInjector (/Volumes/OSxData/websites/startapp/portal/public/lib/angular/angular.js:4007)
  at /Volumes/OSxData/websites/startapp/portal/public/lib/sinon-ng/sinon-ng.js:4
  at /Volumes/OSxData/websites/startapp/portal/public/lib/sinon-ng/sinon-ng.js:30

this occurs in angular-mocks therefore relevant only in testing environment

Reproducable: always
Browsers : Chrome 40, Phantom JS
Operating system: OSX 10.10, Ubuntu 14, Fedora 20

@kuoloneous
Copy link

Also having the same issue.

@kodypeterson
Copy link

+1 Also seeing the same...

@donniewa
Copy link

donniewa commented Feb 4, 2015

+1

1 similar comment
@ricardocasares
Copy link

+1

@brianwider
Copy link

+1 here

@lgalfaso
Copy link
Contributor

lgalfaso commented Feb 4, 2015

@petebacondarwin would like to revert the commit that caused this regression until we have a better solution. WDYT?

@petebacondarwin
Copy link
Contributor

Let's see if we can't fix this but revert before the next release if no joy

@shahata
Copy link
Contributor

shahata commented Feb 4, 2015

This seems to be the same issue that @jeffbcross mentioned for an internal test that failed for him. The fix is easy (initialize the variable to an empty array instead of undefined), but I would like to understand first why this happens and see if I can add a test to protect against this. Taking a deeper look.

@lgalfaso
Copy link
Contributor

lgalfaso commented Feb 4, 2015

Thanks @shahata !

@shahata
Copy link
Contributor

shahata commented Feb 4, 2015

If anyone can post a reproduce it will be very helpful...

@shahata
Copy link
Contributor

shahata commented Feb 4, 2015

OK, the reason for this as I suspected before is that someone is creating an injector before the first beforeEach. In the case of @nadavsinai you can see that the source is sinon-ng which creates an injector immediately on page load in order to get a hold on $q and $timeout (which sounds like a bad idea to me, but never mind that - see https://github.com/boneskull/sinon-ng/blob/master/sinon-ng.js). Anyway, I'll post a simple PR that fixes this but I'm not sure if I want to add a test for this and do something similar in our test suite. @lgalfaso @petebacondarwin - thoughts?

@lgalfaso
Copy link
Contributor

lgalfaso commented Feb 4, 2015

@shahata I think we should add a test to ng-mock to be sure that we do not break this in the future

@kuoloneous
Copy link

Thanks for getting on this so quickly. In our case, our source was https://github.com/cabrel/angular-lodash/blob/master/angular-lodash.js which was causing the issue.

@shahata
Copy link
Contributor

shahata commented Feb 4, 2015

Test added. Though I'm not proud of it :)

shahata added a commit that referenced this issue Feb 6, 2015
This caused an exception for people who created an injector before the tests actually began to run. Since the array was initialized only in beforeEach, anyone accessing it before that would throw. This is solved easily but initializing the array immediately.

Closes #10967
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.