Search code examples
angularjsjasminerestangular

Testing a Restangular responseInterceptor


What is the best way to do a unit test on a Restangular responseInterceptor?

For instance:

.config(['RestangularProvider', function(RestangularProvider){
    RestangularProvider.setDefaultHttpFields({cache: true, withCredentials: true});
    RestangularProvider.addResponseInterceptor(function (data, operation, what, url, response, deferred) {
        console.log('response from '+ url);
        console.log(data);
        var extractedData;
        // .. to look for getList operations
        if (operation === "getList") {
            // .. and handle the data and meta data
            extractedData = data.data;
            //extractedData.meta = data;
        } else {
            extractedData = data;
        }
        return extractedData;
    });
}])

Solution

  • I finally resolved to have this bit of code untested. It's essentially a cut and paste from Restangular's documentation anyhow, and other code would be broken if it was broken, as it affects the format that Restangular provides in the rest of the code.