diff options
| author | Igor Minar | 2011-11-24 03:40:27 -0800 | 
|---|---|---|
| committer | Igor Minar | 2011-11-30 14:49:35 -0500 | 
| commit | bf8e0540f8195edbaaa3d0138bd6a26e79e1ab58 (patch) | |
| tree | ea48170398532062bb2e41754e83a82ebeabf92e | |
| parent | 78b6e8a446c0e38075c14b724f3cdf345c01fa06 (diff) | |
| download | angular.js-bf8e0540f8195edbaaa3d0138bd6a26e79e1ab58.tar.bz2 | |
feat(dump): add support for arrays, functions, errors
| -rw-r--r-- | src/angular-mocks.js | 47 | 
1 files changed, 31 insertions, 16 deletions
| diff --git a/src/angular-mocks.js b/src/angular-mocks.js index 6f69f0d6..903e6ff1 100644 --- a/src/angular-mocks.js +++ b/src/angular-mocks.js @@ -534,24 +534,38 @@ angular.module.ngMock.TzDate.prototype = Date.prototype;   * @return a serialized string of the argument   */  angular.module.ngMock.dump = function(object){ -  var out; -  if (angular.isElement(object)) { -    object = angular.element(object); -    out = angular.element('<div></div>') -    angular.forEach(object, function(element){ -      out.append(angular.element(element).clone()); -    }); -    out = out.html(); -  } else if (angular.isObject(object)) { -    if (angular.isFunction(object.$eval) && angular.isFunction(object.$apply)) { -      out = serializeScope(object); +  return serialize(object); + +  function serialize(object) { +    var out; + +    if (angular.isElement(object)) { +      object = angular.element(object); +      out = angular.element('<div></div>') +      angular.forEach(object, function(element){ +        out.append(angular.element(element).clone()); +      }); +      out = out.html(); +    } else if (angular.isArray(object)) { +      out = []; +      angular.forEach(object, function(o) { +        out.push(serialize(o)); +      }); +      out = '[ ' + out.join(', ') + ' ]'; +    } else if (angular.isObject(object)) { +      if (angular.isFunction(object.$eval) && angular.isFunction(object.$apply)) { +        out = serializeScope(object); +      } else if (object instanceof Error) { +        out = object.stack || ('' + object.name + ': ' + object.message); +      } else { +        out = angular.toJson(object, true); +      }      } else { -      out = angular.toJson(object, true); +      out = String(object);      } -  } else { -    out = String(object); + +    return out;    } -  return out;    function serializeScope(scope, offset) {      offset = offset ||  '  '; @@ -666,8 +680,9 @@ angular.module.ngMock.$HttpBackendProvider = function() {            responses.shift()();          }        } else { -        while (responses.length) +        while (responses.length) {            responses.shift()(); +        }        }        $httpBackend.verifyNoOutstandingExpectation();      }; | 
