mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-20 04:11:51 +00:00
feat(dump): add support for arrays, functions, errors
This commit is contained in:
parent
78b6e8a446
commit
bf8e0540f8
1 changed files with 31 additions and 16 deletions
47
src/angular-mocks.js
vendored
47
src/angular-mocks.js
vendored
|
|
@ -534,24 +534,38 @@ angular.module.ngMock.TzDate.prototype = Date.prototype;
|
||||||
* @return a serialized string of the argument
|
* @return a serialized string of the argument
|
||||||
*/
|
*/
|
||||||
angular.module.ngMock.dump = function(object){
|
angular.module.ngMock.dump = function(object){
|
||||||
var out;
|
return serialize(object);
|
||||||
if (angular.isElement(object)) {
|
|
||||||
object = angular.element(object);
|
function serialize(object) {
|
||||||
out = angular.element('<div></div>')
|
var out;
|
||||||
angular.forEach(object, function(element){
|
|
||||||
out.append(angular.element(element).clone());
|
if (angular.isElement(object)) {
|
||||||
});
|
object = angular.element(object);
|
||||||
out = out.html();
|
out = angular.element('<div></div>')
|
||||||
} else if (angular.isObject(object)) {
|
angular.forEach(object, function(element){
|
||||||
if (angular.isFunction(object.$eval) && angular.isFunction(object.$apply)) {
|
out.append(angular.element(element).clone());
|
||||||
out = serializeScope(object);
|
});
|
||||||
|
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 {
|
} else {
|
||||||
out = angular.toJson(object, true);
|
out = String(object);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
out = String(object);
|
return out;
|
||||||
}
|
}
|
||||||
return out;
|
|
||||||
|
|
||||||
function serializeScope(scope, offset) {
|
function serializeScope(scope, offset) {
|
||||||
offset = offset || ' ';
|
offset = offset || ' ';
|
||||||
|
|
@ -666,8 +680,9 @@ angular.module.ngMock.$HttpBackendProvider = function() {
|
||||||
responses.shift()();
|
responses.shift()();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while (responses.length)
|
while (responses.length) {
|
||||||
responses.shift()();
|
responses.shift()();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$httpBackend.verifyNoOutstandingExpectation();
|
$httpBackend.verifyNoOutstandingExpectation();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue