fix(e2e $httpBackend): use browser.defer instead of $defer

this is necessary to avoid $apply from within $apply situations
This commit is contained in:
Igor Minar 2012-01-16 02:57:35 -08:00
parent b587091b6e
commit 54581d36df

14
src/angular-mocks.js vendored
View file

@ -760,15 +760,15 @@ angular.mock.$HttpBackendProvider = function() {
* - passing through is disabled * - passing through is disabled
* - auto flushing is disabled * - auto flushing is disabled
* *
* Returns instance for e2e testing (when `$delegate` and `$defer` specified): * Returns instance for e2e testing (when `$delegate` and `$browser` specified):
* - passing through (delegating request to real backend) is enabled * - passing through (delegating request to real backend) is enabled
* - auto flushing is enabled * - auto flushing is enabled
* *
* @param {Object=} $delegate Real $httpBackend instance (allow passing through if specified) * @param {Object=} $delegate Real $httpBackend instance (allow passing through if specified)
* @param {Object=} $defer Auto-flushing enabled if specified * @param {Object=} $browser Auto-flushing enabled if specified
* @return {Object} Instance of $httpBackend mock * @return {Object} Instance of $httpBackend mock
*/ */
function createHttpBackendMock($delegate, $defer) { function createHttpBackendMock($delegate, $browser) {
var definitions = [], var definitions = [],
expectations = [], expectations = [],
responses = [], responses = [],
@ -823,8 +823,8 @@ function createHttpBackendMock($delegate, $defer) {
while ((definition = definitions[++i])) { while ((definition = definitions[++i])) {
if (definition.match(method, url, data, headers || {})) { if (definition.match(method, url, data, headers || {})) {
if (definition.response) { if (definition.response) {
// if $defer specified, we do auto flush all requests // if $browser specified, we do auto flush all requests
($defer ? $defer : responsesPush)(function() { ($browser ? $browser.defer : responsesPush)(function() {
var response = definition.response(method, url, data, headers); var response = definition.response(method, url, data, headers);
xhr.$$respHeaders = response[2]; xhr.$$respHeaders = response[2];
callback(response[0], response[1], xhr.getAllResponseHeaders()); callback(response[0], response[1], xhr.getAllResponseHeaders());
@ -869,7 +869,7 @@ function createHttpBackendMock($delegate, $defer) {
} }
}; };
if ($defer) { if ($browser) {
chain.passThrough = function() { chain.passThrough = function() {
definition.passThrough = true; definition.passThrough = true;
}; };
@ -1442,7 +1442,7 @@ angular.module('ngMockE2E', ['ng']).config(function($provide) {
* control how a matched request is handled. * control how a matched request is handled.
*/ */
angular.mock.e2e = {}; angular.mock.e2e = {};
angular.mock.e2e.$httpBackendDecorator = ['$delegate', '$defer', createHttpBackendMock]; angular.mock.e2e.$httpBackendDecorator = ['$delegate', '$browser', createHttpBackendMock];