Skip to content

Commit df2d1d0

Browse files
author
Kent C. Dodds
committed
WIP: rename same to deepEqual
1 parent efa4369 commit df2d1d0

File tree

10 files changed

+86
-34
lines changed

10 files changed

+86
-34
lines changed

Diff for: lib/assert.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ x.not = function (val, expected, msg) {
6060
test(val !== expected, create(val, expected, '!==', msg, x.not));
6161
};
6262

63-
x.same = function (val, expected, msg) {
64-
test(deepEqual(val, expected), create(val, expected, '===', msg, x.same));
63+
x.deepEqual = function (val, expected, msg) {
64+
test(deepEqual(val, expected), create(val, expected, '===', msg, x.deepEqual));
6565
};
6666

67-
x.notSame = function (val, expected, msg) {
68-
test(!deepEqual(val, expected), create(val, expected, '!==', msg, x.notSame));
67+
x.notDeepEqual = function (val, expected, msg) {
68+
test(!deepEqual(val, expected), create(val, expected, '!==', msg, x.notDeepEqual));
6969
};
7070

7171
x.throws = function (fn, err, msg) {
@@ -139,3 +139,21 @@ x.regex = function (contents, regex, msg) {
139139
x.ifError = x.error = function (err, msg) {
140140
test(!err, create(err, 'Error', '!==', msg, x.ifError));
141141
};
142+
143+
/*
144+
* deprecated APIs
145+
*/
146+
x.same = function (val, expected, msg) {
147+
deprecationNotice('same()', 'deepEqual()');
148+
return x.deepEqual(val, expected, msg);
149+
};
150+
151+
x.notSame = function (val, expected, msg) {
152+
deprecationNotice('notSame()', 'notDeepEqual()');
153+
return x.notDeepEqual(val, expected, msg);
154+
};
155+
156+
function deprecationNotice(oldApi, newApi) {
157+
console.warn(`DEPRECATION NOTICE: ${oldApi} has been renamed to ${newApi} and will eventually be removed`);
158+
}
159+

Diff for: readme.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Translations: [Español](https://github.com/sindresorhus/ava-docs/blob/master/es
5151
import test from 'ava';
5252

5353
test(t => {
54-
t.same([1, 2], [1, 2]);
54+
t.deepEqual([1, 2], [1, 2]);
5555
});
5656
```
5757

@@ -762,11 +762,11 @@ Assert that `value` is equal to `expected`.
762762

763763
Assert that `value` is not equal to `expected`.
764764

765-
### `.same(value, expected, [message])`
765+
### `.deepEqual(value, expected, [message])`
766766

767767
Assert that `value` is deep equal to `expected`.
768768

769-
### `.notSame(value, expected, [message])`
769+
### `.notDeepEqual(value, expected, [message])`
770770

771771
Assert that `value` is not deep equal to `expected`.
772772

Diff for: test/assert.js

+49-15
Original file line numberDiff line numberDiff line change
@@ -119,51 +119,51 @@ test('.not()', function (t) {
119119
t.end();
120120
});
121121

122-
test('.same()', function (t) {
122+
test('.deepEqual()', function (t) {
123123
t.doesNotThrow(function () {
124-
assert.same({a: 'a'}, {a: 'a'});
124+
assert.deepEqual({a: 'a'}, {a: 'a'});
125125
});
126126

127127
t.doesNotThrow(function () {
128-
assert.same(['a', 'b'], ['a', 'b']);
128+
assert.deepEqual(['a', 'b'], ['a', 'b']);
129129
});
130130

131131
t.throws(function () {
132-
assert.same({a: 'a'}, {a: 'b'});
132+
assert.deepEqual({a: 'a'}, {a: 'b'});
133133
});
134134

135135
t.throws(function () {
136-
assert.same(['a', 'b'], ['a', 'a']);
136+
assert.deepEqual(['a', 'b'], ['a', 'a']);
137137
});
138138

139139
t.throws(function () {
140-
assert.same([['a', 'b'], 'c'], [['a', 'b'], 'd']);
140+
assert.deepEqual([['a', 'b'], 'c'], [['a', 'b'], 'd']);
141141
}, / 'c' ].*? 'd' ]/);
142142

143143
t.throws(function () {
144144
var circular = ['a', 'b'];
145145
circular.push(circular);
146-
assert.same([circular, 'c'], [circular, 'd']);
146+
assert.deepEqual([circular, 'c'], [circular, 'd']);
147147
}, / 'c' ].*? 'd' ]/);
148148

149149
t.end();
150150
});
151151

152-
test('.notSame()', function (t) {
152+
test('.notDeepEqual()', function (t) {
153153
t.doesNotThrow(function () {
154-
assert.notSame({a: 'a'}, {a: 'b'});
154+
assert.notDeepEqual({a: 'a'}, {a: 'b'});
155155
});
156156

157157
t.doesNotThrow(function () {
158-
assert.notSame(['a', 'b'], ['c', 'd']);
158+
assert.notDeepEqual(['a', 'b'], ['c', 'd']);
159159
});
160160

161161
t.throws(function () {
162-
assert.notSame({a: 'a'}, {a: 'a'});
162+
assert.notDeepEqual({a: 'a'}, {a: 'a'});
163163
});
164164

165165
t.throws(function () {
166-
assert.notSame(['a', 'b'], ['a', 'b']);
166+
assert.notDeepEqual(['a', 'b'], ['a', 'b']);
167167
});
168168

169169
t.end();
@@ -259,7 +259,7 @@ test('.ifError()', function (t) {
259259
t.end();
260260
});
261261

262-
test('.same() should not mask RangeError from underlying assert', function (t) {
262+
test('.deepEqual() should not mask RangeError from underlying assert', function (t) {
263263
var Circular = function () {
264264
this.test = this;
265265
};
@@ -268,12 +268,46 @@ test('.same() should not mask RangeError from underlying assert', function (t) {
268268
var b = new Circular();
269269

270270
t.throws(function () {
271-
assert.notSame(a, b);
271+
assert.notDeepEqual(a, b);
272272
});
273273

274274
t.doesNotThrow(function () {
275-
assert.same(a, b);
275+
assert.deepEqual(a, b);
276276
});
277277

278278
t.end();
279279
});
280+
281+
test('.same() should log a deprecation notice', function (t) {
282+
var calledWith;
283+
var originalConsole = console.warn;
284+
console.warn = function () {
285+
calledWith = arguments;
286+
};
287+
288+
assert.same({}, {});
289+
290+
t.true(calledWith[0].indexOf('DEPRECATION NOTICE') !== -1);
291+
t.true(calledWith[0].indexOf('same()') !== -1);
292+
t.true(calledWith[0].indexOf('deepEqual()') !== -1);
293+
294+
console.warn = originalConsole;
295+
t.end();
296+
});
297+
298+
test('.notSame() should log a deprecation notice', function (t) {
299+
var calledWith;
300+
var originalConsole = console.warn;
301+
console.warn = function () {
302+
calledWith = arguments;
303+
};
304+
305+
assert.notSame({foo: 'bar'}, {bar: 'foo'});
306+
307+
t.true(calledWith[0].indexOf('DEPRECATION NOTICE') !== -1);
308+
t.true(calledWith[0].indexOf('notSame()') !== -1);
309+
t.true(calledWith[0].indexOf('notDeepEqual()') !== -1);
310+
311+
console.warn = originalConsole;
312+
t.end();
313+
});

Diff for: test/fixture/circular-reference-on-assertion.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import test from '../../';
33
test(t => {
44
const circular = ['a', 'b'];
55
circular.push(circular);
6-
t.same([circular, 'c'], [circular, 'd']);
6+
t.deepEqual([circular, 'c'], [circular, 'd']);
77
});

Diff for: test/fixture/pkg-conf/defaults/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ test(t => {
66
t.is(opts.failFast, false);
77
t.is(opts.serial, false);
88
t.is(opts.cacheEnabled, true);
9-
t.same(opts.require, []);
9+
t.deepEqual(opts.require, []);
1010
});

Diff for: test/fixture/pkg-conf/pkg-overrides/actual.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ test(t => {
77
t.is(opts.failFast, true);
88
t.is(opts.serial, true);
99
t.is(opts.cacheEnabled, false);
10-
t.same(opts.require, [
10+
t.deepEqual(opts.require, [
1111
path.join(__dirname, "required.js")
1212
]);
1313
});

Diff for: test/fixture/pkg-conf/precedence/c.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ test('foo', t => {
77
t.is(opts.failFast, false);
88
t.is(opts.serial, false);
99
t.is(opts.cacheEnabled, true);
10-
t.same(opts.match, ['foo*']);
11-
t.same(opts.require, [
10+
t.deepEqual(opts.match, ['foo*']);
11+
t.deepEqual(opts.require, [
1212
path.join(__dirname, "required.js")
1313
]);
1414
});

Diff for: test/fixture/serial.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ test.cb('second', t => {
1717
});
1818

1919
test(t => {
20-
t.same(tests, ['first', 'second']);
20+
t.deepEqual(tests, ['first', 'second']);
2121
});

Diff for: test/hooks.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,12 @@ test('shared context', function (t) {
270270

271271
runner.test(function (a) {
272272
a.context.arr.push('b');
273-
a.same(a.context.arr, ['a', 'b']);
273+
a.deepEqual(a.context.arr, ['a', 'b']);
274274
});
275275

276276
runner.afterEach(function (a) {
277277
a.context.arr.push('c');
278-
a.same(a.context.arr, ['a', 'b', 'c']);
278+
a.deepEqual(a.context.arr, ['a', 'b', 'c']);
279279
});
280280

281281
runner.run({}).then(function () {

Diff for: test/test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ test('handle non-assertion errors even when planned', function (t) {
166166

167167
test('handle testing of arrays', function (t) {
168168
var result = ava(function (a) {
169-
a.same(['foo', 'bar'], ['foo', 'bar']);
169+
a.deepEqual(['foo', 'bar'], ['foo', 'bar']);
170170
}).run();
171171

172172
t.is(result.passed, true);
@@ -176,7 +176,7 @@ test('handle testing of arrays', function (t) {
176176

177177
test('handle falsy testing of arrays', function (t) {
178178
var result = ava(function (a) {
179-
a.notSame(['foo', 'bar'], ['foo', 'bar', 'cat']);
179+
a.notDeepEqual(['foo', 'bar'], ['foo', 'bar', 'cat']);
180180
}).run();
181181

182182
t.is(result.passed, true);
@@ -186,7 +186,7 @@ test('handle falsy testing of arrays', function (t) {
186186

187187
test('handle testing of objects', function (t) {
188188
var result = ava(function (a) {
189-
a.same({foo: 'foo', bar: 'bar'}, {foo: 'foo', bar: 'bar'});
189+
a.deepEqual({foo: 'foo', bar: 'bar'}, {foo: 'foo', bar: 'bar'});
190190
}).run();
191191

192192
t.is(result.passed, true);
@@ -196,7 +196,7 @@ test('handle testing of objects', function (t) {
196196

197197
test('handle falsy testing of objects', function (t) {
198198
var result = ava(function (a) {
199-
a.notSame({foo: 'foo', bar: 'bar'}, {foo: 'foo', bar: 'bar', cat: 'cake'});
199+
a.notDeepEqual({foo: 'foo', bar: 'bar'}, {foo: 'foo', bar: 'bar', cat: 'cake'});
200200
}).run();
201201

202202
t.is(result.passed, true);

0 commit comments

Comments
 (0)