Skip to content

Commit b122714

Browse files
BridgeARjasnell
authored andcommittedSep 25, 2017
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 8eeaba6 commit b122714

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
@@ -518,62 +518,6 @@ a.throws(makeBlock(thrower, TypeError), function(err) {
518518
assert.ok(threw);
519519
}
520520

521-
// https://github.com/nodejs/node/issues/6416
522-
// Make sure circular refs don't throw.
523-
{
524-
const b = {};
525-
b.b = b;
526-
527-
const c = {};
528-
c.b = c;
529-
530-
a.doesNotThrow(makeBlock(a.deepEqual, b, c));
531-
a.doesNotThrow(makeBlock(a.deepStrictEqual, b, c));
532-
533-
const d = {};
534-
d.a = 1;
535-
d.b = d;
536-
537-
const e = {};
538-
e.a = 1;
539-
e.b = e.a;
540-
541-
a.throws(makeBlock(a.deepEqual, d, e), /AssertionError/);
542-
a.throws(makeBlock(a.deepStrictEqual, d, e), /AssertionError/);
543-
544-
// https://github.com/nodejs/node/issues/13314
545-
const f = {};
546-
f.ref = f;
547-
548-
const g = {};
549-
g.ref = g;
550-
551-
const h = { ref: g };
552-
553-
a.doesNotThrow(makeBlock(a.deepEqual, f, h));
554-
a.doesNotThrow(makeBlock(a.deepStrictEqual, f, h));
555-
}
556-
// GH-7178. Ensure reflexivity of deepEqual with `arguments` objects.
557-
const args = (function() { return arguments; })();
558-
a.throws(makeBlock(a.deepEqual, [], args));
559-
a.throws(makeBlock(a.deepEqual, args, []));
560-
561-
// more checking that arguments objects are handled correctly
562-
{
563-
// eslint-disable-next-line func-style
564-
const returnArguments = function() { return arguments; };
565-
566-
const someArgs = returnArguments('a');
567-
const sameArgs = returnArguments('a');
568-
const diffArgs = returnArguments('b');
569-
570-
a.throws(makeBlock(a.deepEqual, someArgs, ['a']));
571-
a.throws(makeBlock(a.deepEqual, ['a'], someArgs));
572-
a.throws(makeBlock(a.deepEqual, someArgs, { '0': 'a' }));
573-
a.throws(makeBlock(a.deepEqual, someArgs, diffArgs));
574-
a.doesNotThrow(makeBlock(a.deepEqual, someArgs, sameArgs));
575-
}
576-
577521
// check messages from assert.throws()
578522
{
579523
const noop = () => {};

0 commit comments

Comments
 (0)
Please sign in to comment.