Created
October 29, 2013 06:23
-
-
Save emiaj/7209915 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Global jasmine hook to prevent errors when attempt to | |
| // download a localization .json file in test environment. | |
| // Here we are resetting the translate provider to a | |
| // safe state. | |
| // If a test needs to assert for localized texts, | |
| // the test author is free to setup the translate provider | |
| // on isolation by overriding its settings. | |
| // This wont affect other tests because once the test execution | |
| // exits, the translate provider is reset once again to | |
| // a safe state. | |
| // The error we get if we do not add this global hook is: | |
| // Error: Unexpected request: GET /locale.en.json | |
| // No more request expected | |
| // https://github.com/PascalPrecht/angular-translate/issues/42 | |
| beforeEach(function() { | |
| var DEFAULT_LANG = 'en'; | |
| var DEFAULT_TRANSLATIONS = {}; | |
| var MODULE_NAME = 'myapp.i18n'; // UPDATE ACCORDINGLY | |
| module(MODULE_NAME, function config($translateProvider) { | |
| $translateProvider.translations(DEFAULT_LANG, DEFAULT_TRANSLATIONS); | |
| $translateProvider.preferredLanguage(DEFAULT_LANG); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@emiaj, how are you calling this "global hook" in Karma?
I'm running a Yeoman-scaffolded project that sources everything in
tests/mock/**/*.jsbefore running the actual specs. I've tried adding your snippet above into a mock module and adding it as a dependency to each spec, to no avail.