Skip to content

Commit

Permalink
inspect: Add test for circular object as result of custom inspect
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Mar 15, 2019
1 parent 1375776 commit ffccf3f
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions src/jsutils/__tests__/inspect-test.js
Expand Up @@ -86,27 +86,6 @@ describe('inspect', () => {
expect(inspect(map)).to.equal('{ a: true, b: null }');
});

it('detect circular objects', () => {
const obj = {};
obj.self = obj;
obj.deepSelf = { self: obj };

expect(inspect(obj)).to.equal(
'{ self: [Circular], deepSelf: { self: [Circular] } }',
);

const array = [];
array[0] = array;
array[1] = [array];

expect(inspect(array)).to.equal('[[Circular], [[Circular]]]');

const mixed = { array: [] };
mixed.array[0] = mixed;

expect(inspect(mixed)).to.equal('{ array: [[Circular]] }');
});

it('custom inspect', () => {
const object = {
inspect() {
Expand Down Expand Up @@ -163,6 +142,37 @@ describe('inspect', () => {
expect(inspect(object)).to.equal('Hello World!');
});

it('detect circular objects', () => {
const obj = {};
obj.self = obj;
obj.deepSelf = { self: obj };

expect(inspect(obj)).to.equal(
'{ self: [Circular], deepSelf: { self: [Circular] } }',
);

const array = [];
array[0] = array;
array[1] = [array];

expect(inspect(array)).to.equal('[[Circular], [[Circular]]]');

const mixed = { array: [] };
mixed.array[0] = mixed;

expect(inspect(mixed)).to.equal('{ array: [[Circular]] }');

const customA = {
inspect: () => customB,
};

const customB = {
inspect: () => customA,
};

expect(inspect(customA)).to.equal('[Circular]');
});

it('Use class names for the shortform of an object', () => {
class Foo {
foo: string;
Expand Down

0 comments on commit ffccf3f

Please sign in to comment.