Skip to content

Commit 8db3997

Browse files
BridgeARtniessen
authored andcommitted
test: clean up some assert deepEqual tests
PR-URL: #14491 Fixes: #14441 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
1 parent a8149c4 commit 8db3997

File tree

2 files changed

+52
-66
lines changed

2 files changed

+52
-66
lines changed

test/parallel/test-assert-deep.js

+52-10
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,17 @@ assertNotDeepOrStrict(new Set([1, 2, 3, 4]), new Set([1, 2, 3]));
159159
assertDeepAndStrictEqual(new Set(['1', '2', '3']), new Set(['1', '2', '3']));
160160
assertDeepAndStrictEqual(new Set([[1, 2], [3, 4]]), new Set([[3, 4], [1, 2]]));
161161

162-
const a = [ 1, 2 ];
163-
const b = [ 3, 4 ];
164-
const c = [ 1, 2 ];
165-
const d = [ 3, 4 ];
166-
167-
assertDeepAndStrictEqual(
168-
{ a: a, b: b, s: new Set([a, b]) },
169-
{ a: c, b: d, s: new Set([d, c]) }
170-
);
162+
{
163+
const a = [ 1, 2 ];
164+
const b = [ 3, 4 ];
165+
const c = [ 1, 2 ];
166+
const d = [ 3, 4 ];
167+
168+
assertDeepAndStrictEqual(
169+
{ a: a, b: b, s: new Set([a, b]) },
170+
{ a: c, b: d, s: new Set([d, c]) }
171+
);
172+
}
171173

172174
assertDeepAndStrictEqual(new Map([[1, 1], [2, 2]]), new Map([[1, 1], [2, 2]]));
173175
assertDeepAndStrictEqual(new Map([[1, 1], [2, 2]]), new Map([[2, 2], [1, 1]]));
@@ -303,7 +305,26 @@ assertOnlyDeepEqual(
303305
new Set([undefined])
304306
);
305307

306-
// Circular structures
308+
// GH-6416. Make sure circular refs don't throw.
309+
{
310+
const b = {};
311+
b.b = b;
312+
const c = {};
313+
c.b = c;
314+
315+
assertDeepAndStrictEqual(b, c);
316+
317+
const d = {};
318+
d.a = 1;
319+
d.b = d;
320+
const e = {};
321+
e.a = 1;
322+
e.b = {};
323+
324+
assertNotDeepOrStrict(d, e);
325+
}
326+
327+
// GH-14441. Circular structures should be consistent
307328
{
308329
const a = {};
309330
const b = {};
@@ -323,6 +344,27 @@ assertOnlyDeepEqual(
323344
assertDeepAndStrictEqual(b, c);
324345
}
325346

347+
// GH-7178. Ensure reflexivity of deepEqual with `arguments` objects.
348+
{
349+
const args = (function() { return arguments; })();
350+
assertNotDeepOrStrict([], args);
351+
}
352+
353+
// More checking that arguments objects are handled correctly
354+
{
355+
// eslint-disable-next-line func-style
356+
const returnArguments = function() { return arguments; };
357+
358+
const someArgs = returnArguments('a');
359+
const sameArgs = returnArguments('a');
360+
const diffArgs = returnArguments('b');
361+
362+
assertNotDeepOrStrict(someArgs, ['a']);
363+
assertNotDeepOrStrict(someArgs, { '0': 'a' });
364+
assertNotDeepOrStrict(someArgs, diffArgs);
365+
assertDeepAndStrictEqual(someArgs, sameArgs);
366+
}
367+
326368
{
327369
const values = [
328370
123,

test/parallel/test-assert.js

-56
Original file line numberDiff line numberDiff line change
@@ -546,62 +546,6 @@ a.throws(makeBlock(thrower, TypeError), function(err) {
546546
assert.ok(threw);
547547
}
548548

549-
// https://github.com/nodejs/node/issues/6416
550-
// Make sure circular refs don't throw.
551-
{
552-
const b = {};
553-
b.b = b;
554-
555-
const c = {};
556-
c.b = c;
557-
558-
a.doesNotThrow(makeBlock(a.deepEqual, b, c));
559-
a.doesNotThrow(makeBlock(a.deepStrictEqual, b, c));
560-
561-
const d = {};
562-
d.a = 1;
563-
d.b = d;
564-
565-
const e = {};
566-
e.a = 1;
567-
e.b = e.a;
568-
569-
a.throws(makeBlock(a.deepEqual, d, e), /AssertionError/);
570-
a.throws(makeBlock(a.deepStrictEqual, d, e), /AssertionError/);
571-
572-
// https://github.com/nodejs/node/issues/13314
573-
const f = {};
574-
f.ref = f;
575-
576-
const g = {};
577-
g.ref = g;
578-
579-
const h = { ref: g };
580-
581-
a.doesNotThrow(makeBlock(a.deepEqual, f, h));
582-
a.doesNotThrow(makeBlock(a.deepStrictEqual, f, h));
583-
}
584-
// GH-7178. Ensure reflexivity of deepEqual with `arguments` objects.
585-
const args = (function() { return arguments; })();
586-
a.throws(makeBlock(a.deepEqual, [], args));
587-
a.throws(makeBlock(a.deepEqual, args, []));
588-
589-
// more checking that arguments objects are handled correctly
590-
{
591-
// eslint-disable-next-line func-style
592-
const returnArguments = function() { return arguments; };
593-
594-
const someArgs = returnArguments('a');
595-
const sameArgs = returnArguments('a');
596-
const diffArgs = returnArguments('b');
597-
598-
a.throws(makeBlock(a.deepEqual, someArgs, ['a']));
599-
a.throws(makeBlock(a.deepEqual, ['a'], someArgs));
600-
a.throws(makeBlock(a.deepEqual, someArgs, { '0': 'a' }));
601-
a.throws(makeBlock(a.deepEqual, someArgs, diffArgs));
602-
a.doesNotThrow(makeBlock(a.deepEqual, someArgs, sameArgs));
603-
}
604-
605549
// check messages from assert.throws()
606550
{
607551
const noop = () => {};

0 commit comments

Comments
 (0)