Wednesday, 11 September 2013

How to run Unit Tests in Angular with dependency on a global

How to run Unit Tests in Angular with dependency on a global

I'm trying to use a i18n module called lingua in a new angular project
(based on ng-boiletplate). You can find this module and a short
instruction on github
I think it's a great approach bringing gettext style i18n to angular. The
integration as mentioned on the github readme did work flawlessly.
But with the integration as it is, based on a manual bootstrap of angular
I'm not able to run my tests.
angular.element(document).ready(function() {
Lingua.init(document, function() {
angular.bootstrap(document, ['modulename']);
});
});
My project is at the moment based on the angular phonecat tutorial. Ang
when running the tests I get this error because of the global i18n which
should be declared in the "Lingua.init" method before the bootstrap of
angular.
ReferenceError: i18n is not defined in /path/to/lingua/lingua.js (line 54)
Is there a possibility to run that custom bootstrap before the tests get
executed? Or is there a way to mock the global?
I'm pretty new to angular, but i realy like the gettext style compared to
other i18n modules for angular out there.
I'm in hope someone can give me a hint, because this problem is annoying
me for days now ;-(

No comments:

Post a Comment