Include function names in pretty printer output
This helps make matcher errors and spy strategy mismatch errors easier to understand in cases where the difference involves expecting one function but getting a different one.
This commit is contained in:
@@ -164,7 +164,7 @@ describe('PrettyPrinter', function() {
|
||||
"Object({ foo: 'bar', baz: 3, nullValue: null, undefinedValue: undefined })"
|
||||
);
|
||||
expect(pp({ foo: function() {}, bar: [1, 2, 3] })).toEqual(
|
||||
'Object({ foo: Function, bar: [ 1, 2, 3 ] })'
|
||||
"Object({ foo: Function 'foo', bar: [ 1, 2, 3 ] })"
|
||||
);
|
||||
});
|
||||
|
||||
@@ -450,7 +450,7 @@ describe('PrettyPrinter', function() {
|
||||
};
|
||||
|
||||
expect(pp(objFromOtherContext)).toEqual(
|
||||
"Object({ foo: 'bar', toString: Function })"
|
||||
"Object({ foo: 'bar', toString: Function 'toString' })"
|
||||
);
|
||||
});
|
||||
|
||||
@@ -477,6 +477,17 @@ describe('PrettyPrinter', function() {
|
||||
expect(pp(a)).toEqual('<anonymous>({ })');
|
||||
});
|
||||
|
||||
it('stringifies functions with names', function() {
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp(foo)).toEqual("Function 'foo'");
|
||||
function foo() {}
|
||||
});
|
||||
|
||||
it('stringifies functions without names', function() {
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp(function() {})).toEqual('Function');
|
||||
});
|
||||
|
||||
it('should handle objects with null prototype', function() {
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const obj = Object.create(null);
|
||||
|
||||
@@ -458,9 +458,9 @@ describe('toEqual', function() {
|
||||
});
|
||||
|
||||
it('reports mismatches between Functions', function() {
|
||||
const actual = { x: function() {} },
|
||||
expected = { x: function() {} },
|
||||
message = 'Expected $.x = Function to equal Function.';
|
||||
const actual = { x: function() {} };
|
||||
const expected = { x: function() {} };
|
||||
const message = "Expected $.x = Function 'x' to equal Function 'x'.";
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user