10000 Remove the custom "is" matcher in favor of "toEqual" (#1341) · lisongyu/immutable-js@d267ac2 · GitHub
[go: up one dir, main page]

Skip to content

Commit d267ac2

Browse files
authored
Remove the custom "is" matcher in favor of "toEqual" (immutable-js#1341)
jest has dramatically improved over the years, and supports Immutable values directly! No need for our custom checker.
1 parent a976172 commit d267ac2

File tree

4 files changed

+19
-103
lines changed

4 files changed

+19
-103
lines changed

__tests__/Conversion.ts

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,6 @@ import * as jasmineCheck from "jasmine-check";
1111
import {fromJS, is, List, Map, OrderedMap, Record} from "../";
1212
jasmineCheck.install();
1313

14-
declare function expect(val: any): ExpectWithIs;
15-
16-
interface ExpectWithIs extends Expect {
17-
is(expected: any): void;
18-
not: ExpectWithIs;
19-
}
20-
21-
jasmine.addMatchers({
22-
is() {
23-
return {
24-
compare(actual, expected) {
25-
let passed = is(actual, expected);
26-
return {
27-
pass: passed,
28-
message: 'Expected ' + actual + (passed ? '' : ' not') + ' to equal ' + expected,
29-
};
30-
},
31-
};
32-
},
33-
});
34-
3514
// Symbols
3615
declare function Symbol(name: string): Object;
3716

@@ -131,7 +110,7 @@ describe('Conversion', () => {
131110
let nonStringKeyMapString = 'OrderedMap { 1: true, false: "foo" }';
132111

133112
it('Converts deep JS to deep immutable sequences', () => {
134-
expect(fromJS(js)).is(immutableData);
113+
expect(fromJS(js)).toEqual(immutableData);
135114
});
136115

137116
it('Throws when provided circular reference', () => {
@@ -149,8 +128,8 @@ describe('Conversion', () => {
149128
}
150129
return Array.isArray(this[key]) ? sequence.toList() : sequence.toOrderedMap();
151130
});
152-
expect(seq).is(immutableOrderedData);
153-
expect(seq.toString()).is(immutableOrderedDataString);
131+
expect(seq).toEqual(immutableOrderedData);
132+
expect(seq.toString()).toEqual(immutableOrderedDataString);
154133
});
155134

156135
it('Converts deep JSON with custom conversion including keypath if requested', () => {
@@ -178,12 +157,12 @@ describe('Conversion', () => {
178157
});
179158

180159
it('Prints keys as JS values', () => {
181-
expect(nonStringKeyMap.toString()).is(nonStringKeyMapString);
160+
expect(nonStringKeyMap.toString()).toEqual(nonStringKeyMapString);
182161
});
183162

184163
it('Converts deep sequences to JS', () => {
185164
let js2 = immutableData.toJS();
186-
expect(js2).not.is(js); // raw JS is not immutable.
165+
expect(is(js2, js)).toBe(false); // raw JS is not immutable.
187166
expect(js2).toEqual(js); // but should be deep equal.
188167
});
189168

@@ -211,7 +190,7 @@ describe('Conversion', () => {
211190
});
212191

213192
it('is conservative with array-likes, only accepting true Arrays.', () => {
214-
expect(fromJS({1: 2, length: 3})).is(
193+
expect(fromJS({1: 2, length: 3})).toEqual(
215194
Map().set('1', 2).set('length', 3),
216195
);
217196
expect(fromJS('string')).toEqual('string');

__tests__/Set.ts

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,6 @@
1010
declare var Symbol: any;
1111
import { is, List, Map, OrderedSet, Seq, Set } from '../';
1212

13-
declare function expect(val: any): ExpectWithIs;
14-
15-
interface ExpectWithIs extends Expect {
16-
is(expected: any): void;
17-
not: ExpectWithIs;
18-
}
19-
20-
jasmine.addMatchers({
21-
is() {
22-
return {
23-
compare(actual, expected) {
24-
let passed = is(actual, expected);
25-
return {
26-
pass: passed,
27-
message: 'Expected ' + actual + (passed ? '' : ' not') + ' to equal ' + expected,
28-
};
29-
},
30-
};
31-
},
32-
});
33-
3413
describe('Set', () => {
3514
it('accepts array of values', () => {
3615
let s = Set([1, 2, 3]);
@@ -211,17 +190,17 @@ describe('Set', () => {
211190

212191
it('unions multiple sets', () => {
213192
let s = Set.of('A', 'B', 'C').union(Set.of('C', 'D', 'E'), Set.of('D', 'B', 'F'));
214-
expect(s).is(Set.of('A', 'B', 'C', 'D', 'E', 'F'));
193+
expect(s).toEqual(Set.of('A', 'B', 'C', 'D', 'E', 'F'));
215194
});
216195

217196
it('intersects multiple sets', () => {
218197
let s = Set.of('A', 'B', 'C').intersect(Set.of('B', 'C', 'D'), Set.of('A', 'C', 'E'));
219-
expect(s).is(Set.of('C'));
198+
expect(s).toEqual(Set.of('C'));
220199
});
221200

222201
it('diffs multiple sets', () => {
223202
let s = Set.of('A', 'B', 'C').subtract(Set.of('C', 'D', 'E'), Set.of('D', 'B', 'F'));
224-
expect(s).is(Set.of('A'));
203+
expect(s).toEqual(Set.of('A'));
225204
});
226205

227206
it('expresses value equality with set sequences', () => {

__tests__/concat.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,12 @@
99

1010
import { is, List, Seq, Set } from '../';
1111

12-
declare function expect(val: any): ExpectWithIs;
13-
14-
interface ExpectWithIs extends Expect {
15-
is(expected: any): void;
16-
not: ExpectWithIs;
17-
}
18-
19-
jasmine.addMatchers({
20-
is() {
21-
return {
22-
compare(actual, expected) {
23-
let passed = is(actual, expected);
24-
return {
25-
pass: passed,
26-
message: 'Expected ' + actual + (passed ? '' : ' not') + ' to equal ' + expected,
27-
};
28-
},
29-
};
30-
},
31-
});
32-
3312
describe('concat', () => {
3413

3514
it('concats two sequences', () => {
3615
let a = Seq([1, 2, 3]);
3716
let b = Seq([4, 5, 6]);
38-
expect(a.concat(b)).is(Seq([1, 2, 3, 4, 5, 6]));
17+
expect(is(a.concat(b), Seq([1, 2, 3, 4, 5, 6]))).toBe(true);
3918
expect(a.concat(b).size).toBe(6);
4019
expect(a.concat(b).toArray()).toEqual([1, 2, 3, 4, 5, 6]);
4120
});
@@ -119,7 +98,7 @@ describe('concat', () => {
11998
let b = List();
12099
expect(b.concat(a)).not.toBe(a);
121100
expect(List.isList(b.concat(a))).toBe(true);
122-
expect(b.concat(a)).is(List([1, 2, 3]));
101+
expect(b.concat(a)).toEqual(List([1, 2, 3]));
123102
});
124103

125104
it('iterates repeated keys', () => {

__tests__/merge.ts

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,23 @@
99

1010
import { fromJS, is, List, Map } from '../';
1111

12-
declare function expect(val: any): ExpectWithIs;
13-
14-
interface ExpectWithIs extends Expect {
15-
is(expected: any): void;
16-
not: ExpectWithIs;
17-
}
18-
19-
jasmine.addMatchers({
20-
is() {
21-
return {
22-
compare(actual, expected) {
23-
let passed = is(actual, expected);
24-
return {
25-
pass: passed,
26-
message: 'Expected ' + actual + (passed ? '' : ' not') + ' to equal ' + expected,
27-
};
28-
},
29-
};
30-
},
31-
});
32-
3312
describe('merge', () => {
3413
it('merges two maps', () => {
3514
let m1 = Map({a: 1, b: 2, c: 3});
3615
let m2 = Map({d: 10, b: 20, e: 30});
37-
expect(m1.merge(m2)).is(Map({a: 1, b: 20, c: 3, d: 10, e: 30}));
16+
expect(m1.merge(m2)).toEqual(Map({a: 1, b: 20, c: 3, d: 10, e: 30}));
3817
});
3918

4019
it('can merge in an explicitly undefined value', () => {
4120
let m1 = Map({a: 1, b: 2});
4221
let m2 = Map({a: undefined as any});
43-
expect(m1.merge(m2)).is(Map({a: undefined, b: 2}));
22+
expect(m1.merge(m2)).toEqual(Map({a: undefined, b: 2}));
4423
});
4524

4625
it('merges two maps with a merge function', () => {
4726
let m1 = Map({a: 1, b: 2, c: 3});
4827
let m2 = Map({d: 10, b: 20, e: 30});
49-
expect(m1.mergeWith((a, b) => a + b, m2)).is(Map({a: 1, b: 22, c: 3, d: 10, e: 30}));
28+
expect(m1.mergeWith((a, b) => a + b, m2)).toEqual(Map({a: 1, b: 22, c: 3, d: 10, e: 30}));
5029
});
5130

5231
it('provides key as the third argument of merge function', () => {
@@ -55,13 +34,13 @@ describe('merge', () => {
5534
let add = (a, b) => a + b;
5635
expect(
5736
m1.mergeWith((a, b, key) => key !== 'id' ? add(a, b) : b, m2),
58-
).is(Map({id: 10, b: 22, c: 3, e: 30}));
37+
).toEqual(Map({id: 10, b: 22, c: 3, e: 30}));
5938
});
6039

6140
it('deep merges two maps', () => {
6241
let m1 = fromJS({a: {b: {c: 1, d: 2}}});
6342
let m2 = fromJS({a: {b: {c: 10, e: 20}, f: 30}, g: 40});
64-
expect(m1.mergeDeep(m2)).is(fromJS({a: {b: {c: 10, d: 2, e: 20}, f: 30}, g: 40}));
43+
expect(m1.mergeDeep(m2)).toEqual(fromJS({a: {b: {c: 10, d: 2, e: 20}, f: 30}, g: 40}));
6544
});
6645

6746
it('deep merge uses is() for return-self optimization', () => {
@@ -75,15 +54,15 @@ describe('merge', () => {
7554
it('deep merges raw JS', () => {
7655
let m1 = fromJS({a: {b: {c: 1, d: 2}}});
7756
let js = {a: {b: {c: 10, e: 20}, f: 30}, g: 40};
78-
expect(m1.mergeDeep(js)).is(fromJS({a: {b: {c: 10, d: 2, e: 20}, f: 30}, g: 40}));
57+
expect(m1.mergeDeep(js)).toEqual(fromJS({a: {b: {c: 10, d: 2, e: 20}, f: 30}, g: 40}));
7958
});
8059

8160
it('deep merges raw JS with a merge function', () => {
8261
let m1 = fromJS({a: {b: {c: 1, d: 2}}});
8362
let js = {a: {b: {c: 10, e: 20}, f: 30}, g: 40};
8463
expect(
8564
m1.mergeDeepWith((a, b) => a + b, js),
86-
).is(fromJS(
65+
).toEqual(fromJS(
8766
{a: {b: {c: 11, d: 2, e: 20}, f: 30}, g: 40},
8867
));
8968
});
@@ -152,7 +131,7 @@ describe('merge', () => {
152131
Map({a: Map({b: List.of( {plain: 'obj'} )})}),
153132
);
154133

155-
expect(m1.getIn(['a', 'b', 0])).is(Map([['imm', 'map']]));
134+
expect(m1.getIn(['a', 'b', 0])).toEqual(Map([['imm', 'map']]));
156135
// However mergeDeep will merge that value into the inner Map
157136
expect(m2.getIn(['a', 'b', 0])).toEqual(Map({imm: 'map', plain: 'obj'}));
158137
});

0 commit comments

Comments
 (0)
0