Created
June 27, 2015 04:48
-
-
Save lucasfeliciano/5e68a6a740259cfcd942 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
'use strict'; | |
angular.module('moduleName') | |
.config(function($provide) { | |
$provide.decorator('$httpBackend', angular.mock.e2e.$httpBackendDecorator); | |
}) | |
.config(function ($httpProvider) { | |
$httpProvider.interceptors.push(function($q, $timeout, $log) { | |
return { | |
'request': function(config) { | |
var deferred = $q.defer(), | |
// Random response time | |
delay = _.random(20, 500); | |
$timeout(function() { | |
$log.log('Request ' + config.url , ' Delayed: ' + delay , config); | |
deferred.resolve(config); | |
}, delay); | |
return deferred.promise; | |
//return config; | |
}, | |
'response': function(response) { | |
var deferred = $q.defer(), | |
delay = _.random(20, 500); | |
if (response.config.url.indexOf('views/') === 0) { | |
return response; | |
} | |
$timeout(function() { | |
$log.log('Response ' + response.config.url , ' Delayed: ' + delay , response); | |
deferred.resolve(response); | |
}, delay); | |
return deferred.promise; | |
} | |
}; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment