Skip to content

Commit fadbc78

Browse files
committed
inspect: Add test for circular object as result of custom inspect
1 parent 2700388 commit fadbc78

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

src/jsutils/__tests__/inspect-test.js

+31-21
Original file line numberDiff line numberDiff line change
@@ -86,27 +86,6 @@ describe('inspect', () => {
8686
expect(inspect(map)).to.equal('{ a: true, b: null }');
8787
});
8888

89-
it('detect circular objects', () => {
90-
const obj = {};
91-
obj.self = obj;
92-
obj.deepSelf = { self: obj };
93-
94-
expect(inspect(obj)).to.equal(
95-
'{ self: [Circular], deepSelf: { self: [Circular] } }',
96-
);
97-
98-
const array = [];
99-
array[0] = array;
100-
array[1] = [array];
101-
102-
expect(inspect(array)).to.equal('[[Circular], [[Circular]]]');
103-
104-
const mixed = { array: [] };
105-
mixed.array[0] = mixed;
106-
107-
expect(inspect(mixed)).to.equal('{ array: [[Circular]] }');
108-
});
109-
11089
it('custom inspect', () => {
11190
const object = {
11291
inspect() {
@@ -163,6 +142,37 @@ describe('inspect', () => {
163142
expect(inspect(object)).to.equal('Hello World!');
164143
});
165144

145+
it('detect circular objects', () => {
146+
const obj = {};
147+
obj.self = obj;
148+
obj.deepSelf = { self: obj };
149+
150+
expect(inspect(obj)).to.equal(
151+
'{ self: [Circular], deepSelf: { self: [Circular] } }',
152+
);
153+
154+
const array = [];
155+
array[0] = array;
156+
array[1] = [array];
157+
158+
expect(inspect(array)).to.equal('[[Circular], [[Circular]]]');
159+
160+
const mixed = { array: [] };
161+
mixed.array[0] = mixed;
162+
163+
expect(inspect(mixed)).to.equal('{ array: [[Circular]] }');
164+
165+
const customA = {
166+
inspect: () => customB,
167+
};
168+
169+
const customB = {
170+
inspect: () => customA,
171+
};
172+
173+
expect(inspect(customA)).to.equal('[Circular]');
174+
});
175+
166176
it('Use class names for the shortform of an object', () => {
167177
class Foo {
168178
foo: string;

0 commit comments

Comments
 (0)