diff --git a/spec/suites/PrettyPrintSpec.js b/spec/suites/PrettyPrintSpec.js index 48b1c7d..71f27c4 100644 --- a/spec/suites/PrettyPrintSpec.js +++ b/spec/suites/PrettyPrintSpec.js @@ -32,6 +32,10 @@ describe("jasmine.pp", function () { }, bar: [1, 2, 3]})).toEqual("{ foo : Function, bar : [ 1, 2, 3 ] }"); }); + it("should stringify RegExp objects properly", function() { + expect(jasmine.pp(/x|y|z/)).toEqual("/x|y|z/"); + }); + it("should indicate circular object references", function() { var sampleValue = {foo: 'hello'}; sampleValue.nested = sampleValue; diff --git a/src/PrettyPrinter.js b/src/PrettyPrinter.js index d044753..fb63428 100644 --- a/src/PrettyPrinter.js +++ b/src/PrettyPrinter.js @@ -9,11 +9,9 @@ jasmine.PrettyPrinter = function() { * Formats a value in a nice, human-readable string. * * @param value - * @returns {String} */ jasmine.PrettyPrinter.prototype.format = function(value) { if (this.ppNestLevel_ > 40) { - // return '(jasmine.pp nested too deeply!)'; throw new Error('jasmine.PrettyPrinter: format() nested too deeply!'); } @@ -35,6 +33,8 @@ jasmine.PrettyPrinter.prototype.format = function(value) { this.emitScalar('HTMLNode'); } else if (value instanceof Date) { this.emitScalar('Date(' + value + ')'); + } else if (value instanceof RegExp) { + this.emitScalar(value.toString()); } else if (value.__Jasmine_been_here_before__) { this.emitScalar(''); } else if (jasmine.isArray_(value) || typeof value == 'object') {