Merge branch 'prettyPrintCustomConstructortoString' of https://github.com/mbildner/jasmine into mbildner-prettyPrintCustomConstructortoString
- Fixes #1019 - Merges #1099
This commit is contained in:
@@ -156,7 +156,12 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
j$.fnNameFor = function(func) {
|
j$.fnNameFor = function(func) {
|
||||||
return func.name || func.toString().match(/^\s*function\s*(\w*)\s*\(/)[1];
|
if (func.name) {
|
||||||
|
return func.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
var matches = func.toString().match(/^\s*function\s*(\w*)\s*\(/);
|
||||||
|
return matches ? matches[1] : '<anonymous>';
|
||||||
};
|
};
|
||||||
|
|
||||||
j$.any = function(clazz) {
|
j$.any = function(clazz) {
|
||||||
|
|||||||
@@ -189,6 +189,26 @@ describe("jasmineUnderTest.pp", function () {
|
|||||||
expect(jasmineUnderTest.pp(obj)).toEqual("my toString");
|
expect(jasmineUnderTest.pp(obj)).toEqual("my toString");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should stringify objects from named constructors with custom toString", function () {
|
||||||
|
var MyNamedConstructor = function MyNamedConstructor () {};
|
||||||
|
MyNamedConstructor.toString = function () { return ""; };
|
||||||
|
|
||||||
|
var a = {};
|
||||||
|
a.constructor = MyNamedConstructor;
|
||||||
|
|
||||||
|
expect(jasmineUnderTest.pp(a)).toEqual("MyNamedConstructor({ constructor: Function })");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should stringify objects from anonymous constructors with custom toString", function () {
|
||||||
|
var MyAnonymousConstructor = function () {};
|
||||||
|
MyAnonymousConstructor.toString = function () { return ""; };
|
||||||
|
|
||||||
|
var a = {};
|
||||||
|
a.constructor = MyAnonymousConstructor;
|
||||||
|
|
||||||
|
expect(jasmineUnderTest.pp(a)).toEqual("<anonymous>({ constructor: Function })");
|
||||||
|
});
|
||||||
|
|
||||||
it("should handle objects with null prototype", function() {
|
it("should handle objects with null prototype", function() {
|
||||||
if (jasmine.getEnv().ieVersion < 9) { return; }
|
if (jasmine.getEnv().ieVersion < 9) { return; }
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,12 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
j$.fnNameFor = function(func) {
|
j$.fnNameFor = function(func) {
|
||||||
return func.name || func.toString().match(/^\s*function\s*(\w*)\s*\(/)[1];
|
if (func.name) {
|
||||||
|
return func.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
var matches = func.toString().match(/^\s*function\s*(\w*)\s*\(/);
|
||||||
|
return matches ? matches[1] : '<anonymous>';
|
||||||
};
|
};
|
||||||
|
|
||||||
j$.any = function(clazz) {
|
j$.any = function(clazz) {
|
||||||
|
|||||||
Reference in New Issue
Block a user