Skip to content

Commit e9c6cc2

Browse files
Kent C. Doddssindresorhus
Kent C. Dodds
authored andcommitted
rename t.same() to t.deepEqual()
1 parent e3e1752 commit e9c6cc2

File tree

12 files changed

+64
-40
lines changed

12 files changed

+64
-40
lines changed

Diff for: index.d.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,27 @@ export interface AssertContext {
120120
/**
121121
* Assert that value is deep equal to expected.
122122
*/
123-
same<U>(value: U, expected: U, message?: string): void;
123+
deepEqual<U>(value: U, expected: U, message?: string): void;
124124
/**
125125
* Assert that value is not deep equal to expected.
126126
*/
127-
notSame<U>(value: U, expected: U, message?: string): void;
127+
notDeepEqual<U>(value: U, expected: U, message?: string): void;
128128
/**
129129
* Assert that function throws an error or promise rejects.
130130
* @param error Can be a constructor, regex, error message or validation function.
131131
*/
132+
/**
133+
* DEPRECATED, use `deepEqual`. Assert that value is deep equal to expected.
134+
*/
135+
same<U>(value: U, expected: U, message?: string): void;
136+
/**
137+
* DEPRECATED use `notDeepEqual`. Assert that value is not deep equal to expected.
138+
*/
139+
notSame<U>(value: U, expected: U, message?: string): void;
140+
/**
141+
* Assert that function throws an error or promise rejects.
142+
* @param error Can be a constructor, regex, error message or validation function.
143+
*/
132144
throws(value: Promise<{}>, error?: ErrorValidator, message?: string): Promise<any>;
133145
throws(value: () => void, error?: ErrorValidator, message?: string): any;
134146
/**

Diff for: lib/assert.js

+15-6
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) {
@@ -130,12 +130,21 @@ x.notThrows = function (fn, msg) {
130130
}
131131
};
132132

133-
x.doesNotThrow = util.deprecate(x.notThrows, 't.doesNotThrow is renamed to t.notThrows. The old name still works, but will be removed in AVA 1.0.0. Update your references.');
134-
135133
x.regex = function (contents, regex, msg) {
136134
test(regex.test(contents), create(regex, contents, '===', msg, x.regex));
137135
};
138136

139137
x.ifError = x.error = function (err, msg) {
140138
test(!err, create(err, 'Error', '!==', msg, x.ifError));
141139
};
140+
141+
/*
142+
* deprecated APIs
143+
*/
144+
x.doesNotThrow = util.deprecate(x.notThrows, getDeprecationNotice('doesNotThrow()', 'notThrows()'));
145+
x.same = util.deprecate(x.deepEqual, getDeprecationNotice('same()', 'deepEqual()'));
146+
x.notSame = util.deprecate(x.notDeepEqual, getDeprecationNotice('notSame()', 'notDeepEqual()'));
147+
148+
function getDeprecationNotice(oldApi, newApi) {
149+
return 'DEPRECATION NOTICE: ' + oldApi + ' has been renamed to ' + newApi + ' and will eventually be removed. See https://github.com/jamestalmage/ava-codemods to help upgrade your codebase automatically.';
150+
}

Diff for: lib/enhance-assert.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ module.exports.PATTERNS = [
88
't.false(value, [message])',
99
't.is(value, expected, [message])',
1010
't.not(value, expected, [message])',
11+
't.deepEqual(value, expected, [message])',
12+
't.notDeepEqual(value, expected, [message])',
13+
't.regex(contents, regex, [message])',
14+
// deprecated apis
1115
't.same(value, expected, [message])',
12-
't.notSame(value, expected, [message])',
13-
't.regex(contents, regex, [message])'
16+
't.notSame(value, expected, [message])'
1417
];
1518

1619
module.exports.NON_ENHANCED_PATTERNS = [

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

@@ -777,11 +777,11 @@ Assert that `value` is equal to `expected`.
777777

778778
Assert that `value` is not equal to `expected`.
779779

780-
### `.same(value, expected, [message])`
780+
### `.deepEqual(value, expected, [message])`
781781

782782
Assert that `value` is deep equal to `expected`.
783783

784-
### `.notSame(value, expected, [message])`
784+
### `.notDeepEqual(value, expected, [message])`
785785

786786
Assert that `value` is not deep equal to `expected`.
787787

Diff for: test/assert.js

+15-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,11 +268,11 @@ 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();

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)