Skip to content

Commit 973624d

Browse files
Juansindresorhus
Juan
authored andcommitted
Use not-so-shallow module to improve t.deepEqual() (#777)
1 parent c4e58e3 commit 973624d

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed

lib/assert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22
var util = require('util');
33
var assert = require('core-assert');
4-
var deepEqual = require('only-shallow');
4+
var deepEqual = require('not-so-shallow');
55
var observableToPromise = require('observable-to-promise');
66
var isObservable = require('is-observable');
77
var isPromise = require('is-promise');

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@
125125
"meow": "^3.7.0",
126126
"ms": "^0.7.1",
127127
"multimatch": "^2.1.0",
128+
"not-so-shallow": "^0.1.3",
128129
"object-assign": "^4.0.1",
129130
"observable-to-promise": "^0.4.0",
130-
"only-shallow": "^1.2.0",
131131
"option-chain": "^0.1.0",
132132
"package-hash": "^1.1.0",
133133
"pkg-conf": "^1.0.1",

test/assert.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,88 @@ test('.not()', function (t) {
120120
});
121121

122122
test('.deepEqual()', function (t) {
123+
// Tests starting here are to detect regressions in the underlying libraries
124+
// used to test deep object equality
125+
126+
t.throws(function () {
127+
assert.deepEqual({a: false}, {a: 0});
128+
});
129+
130+
t.doesNotThrow(function () {
131+
assert.deepEqual({a: 'a', b: 'b'}, {b: 'b', a: 'a'});
132+
});
133+
134+
t.doesNotThrow(function () {
135+
assert.deepEqual({a: 'a', b: 'b', c: {d: 'd'}}, {c: {d: 'd'}, b: 'b', a: 'a'});
136+
});
137+
138+
t.throws(function () {
139+
assert.deepEqual([1, 2, 3], [1, 2, 3, 4]);
140+
});
141+
142+
t.doesNotThrow(function () {
143+
assert.deepEqual([1, 2, 3], [1, 2, 3]);
144+
});
145+
146+
t.throws(function () {
147+
assert.deepEqual([1, 2, 3], [1, 2, 3, 4]);
148+
});
149+
150+
t.throws(function () {
151+
var fnA = function (a) {
152+
return a;
153+
};
154+
var fnB = function (a) {
155+
return a;
156+
};
157+
158+
assert.deepEqual(fnA, fnB);
159+
});
160+
161+
t.doesNotThrow(function () {
162+
var x1 = {z: 4};
163+
var y1 = {x: x1};
164+
x1.y = y1;
165+
166+
var x2 = {z: 4};
167+
var y2 = {x: x2};
168+
x2.y = y2;
169+
170+
assert.deepEqual(x1, x2);
171+
});
172+
173+
t.doesNotThrow(function () {
174+
function Foo(a) {
175+
this.a = a;
176+
}
177+
178+
var x = new Foo(1);
179+
var y = new Foo(1);
180+
181+
assert.deepEqual(x, y);
182+
});
183+
184+
t.doesNotThrow(function () {
185+
function Foo(a) {
186+
this.a = a;
187+
}
188+
189+
function Bar(a) {
190+
this.a = a;
191+
}
192+
193+
var x = new Foo(1);
194+
var y = new Bar(1);
195+
196+
assert.deepEqual(x, y);
197+
});
198+
199+
t.throws(function () {
200+
assert.deepEqual({a: 'a', b: 'b', c: {d: false}}, {c: {d: 0}, b: 'b', a: 'a'});
201+
});
202+
203+
// Regression test end here
204+
123205
t.doesNotThrow(function () {
124206
assert.deepEqual({a: 'a'}, {a: 'a'});
125207
});

0 commit comments

Comments
 (0)