fix(PrettyPrint): jasmine.createSpyObj('obj', ['toString']);

The PrettyPrint handler for scalars uses toString() but if that method
has been spyed on, then the stringify fails with
TypeError: Cannot read property 'length' of undefined.

By hanlding this case earlier in format() we avoid the error.

Add unit test covering this case.
This commit is contained in:
johnjbarton
2019-05-20 09:12:05 -07:00
parent e04d3d8a62
commit d1adbdc72b
2 changed files with 21 additions and 0 deletions

View File

@@ -30,6 +30,8 @@ getJasmineRequireObj().pp = function(j$) {
this.emitString(value);
} else if (j$.isSpy(value)) {
this.emitScalar('spy on ' + value.and.identity);
} else if (j$.isSpy(value.toString)) {
this.emitScalar('spy on ' + value.toString.and.identity);
} else if (value instanceof RegExp) {
this.emitScalar(value.toString());
} else if (typeof value === 'function') {