Situation
I have some plain Javascript code in a self executing function, that is loaded with all the other Javascript files. All other Javascript is written as Angular modules, services etc, but this one is an exception.
This piece of code gets a language from local storage and loads the correct i18n file from Angular, before angular is loaded. It makes loading the Angular app itself wait till the correct i18n file is loaded. I named it i18nHelper.js.
Question
My question is, how can I test this piece of code and mock values if I want to. For this specific case I would like to set a language in local storage before the file is script, and later on check if the correct i18n file from Angular is loaded.
Is it possible to mock data before the scripts in you karma config are loaded, or do I have to load the i18nHelper.js file manually. I would then be able to set the localstorage before I manually load the file. If this is the only solution, how would I need to structure my tests that in every unit test I can begin from scratch (i18n files in Angular can not be loaded multiple times).
Aucun commentaire:
Enregistrer un commentaire