lgalfaso / angular-dynamic-locale

Module to be able to change the locale at an angularjs application
http://lgalfaso.github.io/angular-dynamic-locale/
MIT License
322 stars 75 forks source link

Undesired $timeout #123

Closed ghost closed 6 years ago

ghost commented 6 years ago

Hey @lgalfaso , first of all, thanks for the library.

I've recently integrated it with a project I'm working on and noticed that a couple karma tests we have started failing with:

deferred tasks to flush (1): {id: 0, time: 0}

It was a shared behavior between 4 components that weren't $timeout.flush()ing before doing a describe.

After some digging on your library, I found that the culprit seems to be https://github.com/lgalfaso/angular-dynamic-locale/blob/master/dist/tmhDynamicLocale.js#L231 where it will trigger an unwanted $timeout even if a starting locale isn't set. Since this is inside the provider, it will be called no matter what.

Let me know if you need more information :).

Thanks!

lgalfaso commented 6 years ago

Hi, I think I would need a little more information.

$timeout should only be used with IE/Edge. Is this what you are seeing?

A locale should be loaded initially when one of these things happen

  1. There is an initial default locale
  2. There is a locale loaded from another run

Relevant code https://github.com/lgalfaso/angular-dynamic-locale/blob/master/dist/tmhDynamicLocale.js#L237-L239

Are you calling tmhDynamicLocaleProvider.defaultLocale(...)? Are you using a storage that is not the default? If you are using the default local storage (this is based on the browser local storage). Are you cleaning the local storage between tests?

Note, you can change the storage key by doing tmhDynamicLocaleProvider.storageKey('newKey').