mercredi 25 février 2015

Unit testing Angular bootstrapping code

I have an app that uses manual bootstrapping, with a chunk of code that essentially looks like this:



(function() {
'use strict';
angular.element( document ).ready( function () {

function fetchLabels( sLang, labelPath ) {
// retrieves json files, builds an object and injects a constant into an angular module
}

function rMerge( oDestination, oSource ) {
// recursive deep merge function
}

function bootstrapApplication() {
angular.element( document ).ready( function () {
angular.bootstrap( document, [ 'dms.webui' ] );
});
}

fetchLabels( 'en_AU' ).then( bootstrapApplication );

}


It works great - essentially fetches two json files, combines them and injects the result as a constant, then bootstraps the app.


My question is how to unit test these functions? I want to write something to test the fetchLabels() and rMerge() methods, but I'm not sure how to go about it. My first thought was separate the methods out into a service and use it that way, but I wasn't sure if I could actually invoke my own service this way before I've even bootstrapped the application?


Otherwise, can anyone suggest a way to separate out these methods into something standalone that I can test more readily?


Aucun commentaire:

Enregistrer un commentaire