From b0ae4611399192203a1d714540122678dffdb48b Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Thu, 12 Nov 2009 16:49:48 -0500 Subject: [PATCH] Nicer pretty printing of spy objects. --- spec/suites/PrettyPrintSpec.js | 16 ++++++++++++++++ src/PrettyPrinter.js | 2 ++ 2 files changed, 18 insertions(+) diff --git a/spec/suites/PrettyPrintSpec.js b/spec/suites/PrettyPrintSpec.js index 71f27c4..cf5f95a 100644 --- a/spec/suites/PrettyPrintSpec.js +++ b/spec/suites/PrettyPrintSpec.js @@ -73,5 +73,21 @@ describe("jasmine.pp", function () { expect(jasmine.pp(window)).toEqual(""); }); + it("should stringify Date objects properly", function() { + var now = new Date(); + expect(jasmine.pp(now)).toEqual("Date(" + now.toString() + ")"); + }); + + it("should stringify spy objects properly", function() { + var TestObject = { + someFunction: function() { + } + }; + spyOn(TestObject, 'someFunction'); + expect(jasmine.pp(TestObject.someFunction)).toEqual("spy on someFunction"); + + expect(jasmine.pp(jasmine.createSpy("something"))).toEqual("spy on something"); + }); + }); diff --git a/src/PrettyPrinter.js b/src/PrettyPrinter.js index fb63428..16021b6 100644 --- a/src/PrettyPrinter.js +++ b/src/PrettyPrinter.js @@ -27,6 +27,8 @@ jasmine.PrettyPrinter.prototype.format = function(value) { this.emitScalar(value.toString()); } else if (typeof value === 'string') { this.emitString(value); + } else if (jasmine.isSpy(value)) { + this.emitScalar("spy on " + value.identity); } else if (typeof value === 'function') { this.emitScalar('Function'); } else if (typeof value.nodeType === 'number') {