Include symbol keys when pretty-printing objects

* Fixes #1966
This commit is contained in:
Steve Gravrock
2022-05-07 10:05:18 -07:00
parent 694375e4ea
commit 270344bd38
4 changed files with 48 additions and 74 deletions

View File

@@ -84,6 +84,11 @@ describe('PrettyPrinter', function() {
);
});
it('includes symbols', function() {
const pp = jasmineUnderTest.makePrettyPrinter();
expect(pp([1, Symbol('foo'), 2])).toEqual('[ 1, Symbol(foo), 2 ]');
});
it('should truncate arrays that are longer than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH', function() {
const originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
const array = [1, 2, 3];
@@ -163,6 +168,25 @@ describe('PrettyPrinter', function() {
);
});
it('includes symbol keys in objects', function() {
const pp = jasmineUnderTest.makePrettyPrinter();
const obj = {};
obj[Symbol('foo')] = 'bar';
expect(pp(obj)).toEqual("Object({ Symbol(foo): 'bar' })");
});
it('stringifies string and symbol keys differently', function() {
const pp = jasmineUnderTest.makePrettyPrinter();
const symObj = {};
const strObj = {};
const k = 'foo';
const v = 'bar';
symObj[Symbol(k)] = v;
strObj[k] = v;
expect(pp(symObj)).not.toEqual(pp(strObj));
});
it('should stringify objects that almost look like DOM nodes', function() {
const pp = jasmineUnderTest.makePrettyPrinter();
expect(pp({ nodeType: 1 })).toEqual('Object({ nodeType: 1 })');