Skip to content

Commit 7d1fd1e

Browse files
committed
test(jest): upgrade jest to v30+ and refactor testing
1 parent 433c9ed commit 7d1fd1e

19 files changed

Lines changed: 6508 additions & 6105 deletions

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
"@size-limit/preset-small-lib": "^11.1.6",
9595
"@size-limit/webpack": "^11.1.6",
9696
"@size-limit/webpack-why": "^11.1.6",
97-
"@types/jest": "^29.5.13",
97+
"@types/jest": "^30.0.0",
9898
"@types/node": "^22.7.4",
9999
"@typescript-eslint/eslint-plugin": "^8.15.0",
100100
"@typescript-eslint/parser": "^8.15.0",
@@ -112,7 +112,7 @@
112112
"fast-json-patch": "^3.1.1",
113113
"immer": "^10.1.1",
114114
"immutable": "^4.0.0",
115-
"jest": "^29.7.0",
115+
"jest": "^30.0.3",
116116
"jsdoc-tests": "^1.1.0",
117117
"json2csv": "^5.0.7",
118118
"lodash": "^4.17.21",
@@ -124,7 +124,7 @@
124124
"rollup": "^4.9.0",
125125
"seamless-immutable": "^7.1.4",
126126
"size-limit": "^11.1.6",
127-
"ts-jest": "^29.2.5",
127+
"ts-jest": "^29.4.0",
128128
"ts-node": "^10.9.2",
129129
"tslib": "^2.8.1",
130130
"typedoc": "^0.28.4",

test/__snapshots__/apply.test.ts.snap

Lines changed: 5146 additions & 5146 deletions
Large diffs are not rendered by default.

test/apply.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,7 @@ test('different options - apply patches', () => {
12441244
apply(draft, [], {
12451245
enableAutoFreeze: false,
12461246
});
1247-
}).toThrowError(`Cannot apply patches with options to a draft.`);
1247+
}).toThrow(`Cannot apply patches with options to a draft.`);
12481248
},
12491249
{ enableAutoFreeze: true }
12501250
);
@@ -1253,7 +1253,7 @@ test('different options - apply patches', () => {
12531253
test('set - patches', () => {
12541254
expect(() => {
12551255
apply(new Set([0]), [{ op: 'replace', path: [0], value: 1 }]);
1256-
}).toThrowError(`Cannot apply replace patch to set.`);
1256+
}).toThrow(`Cannot apply replace patch to set.`);
12571257
});
12581258

12591259
test('array - patches', () => {
@@ -1264,12 +1264,12 @@ test('array - patches', () => {
12641264
test('unexpected - patches', () => {
12651265
expect(() => {
12661266
apply({ a: {} }, [{ op: 'replace', path: ['__proto__', 'a'], value: 1 }]);
1267-
}).toThrowError(
1267+
}).toThrow(
12681268
`Patching reserved attributes like __proto__ and constructor is not allowed.`
12691269
);
12701270
expect(() => {
12711271
apply({ a: {} }, [{ op: 'replace', path: ['constructor', 'a'], value: 1 }]);
1272-
}).toThrowError(
1272+
}).toThrow(
12731273
`Patching reserved attributes like __proto__ and constructor is not allowed.`
12741274
);
12751275
});

test/create.test.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -932,19 +932,19 @@ describe('freeze', () => {
932932
expect(() => {
933933
// @ts-expect-error
934934
state.bar.a = 3;
935-
}).toThrowError();
935+
}).toThrow();
936936
expect(() => {
937937
// @ts-expect-error
938938
state.list.push({ id: 3 });
939-
}).toThrowError();
939+
}).toThrow();
940940
expect(() => {
941941
// @ts-expect-error
942942
state.list[0].id = 3;
943-
}).toThrowError();
943+
}).toThrow();
944944
expect(() => {
945945
// @ts-expect-error
946946
state.list[1].id = 3;
947-
}).toThrowError();
947+
}).toThrow();
948948

949949
const state1 = create(
950950
state,
@@ -960,15 +960,15 @@ describe('freeze', () => {
960960
expect(() => {
961961
// @ts-expect-error
962962
state1.list[0].id = 3;
963-
}).toThrowError();
963+
}).toThrow();
964964
expect(() => {
965965
// @ts-expect-error
966966
state1.list[1].id = 3;
967-
}).toThrowError();
967+
}).toThrow();
968968
expect(() => {
969969
// @ts-expect-error
970970
state1.bar.a = 4;
971-
}).toThrowError();
971+
}).toThrow();
972972
expect(() => {
973973
// just check runtime mutable
974974
// @ts-ignore
@@ -997,15 +997,15 @@ describe('freeze', () => {
997997
expect(() => {
998998
// @ts-expect-error
999999
state.set.add(4);
1000-
}).toThrowError();
1000+
}).toThrow();
10011001
expect(() => {
10021002
// @ts-expect-error
10031003
state.set.delete(1);
1004-
}).toThrowError();
1004+
}).toThrow();
10051005
expect(() => {
10061006
// @ts-expect-error
10071007
state.set.clear();
1008-
}).toThrowError();
1008+
}).toThrow();
10091009
});
10101010

10111011
test('map', () => {
@@ -1036,15 +1036,15 @@ describe('freeze', () => {
10361036
expect(() => {
10371037
// @ts-expect-error
10381038
state.map.set(4, 4);
1039-
}).toThrowError();
1039+
}).toThrow();
10401040
expect(() => {
10411041
// @ts-expect-error
10421042
state.map.delete(1);
1043-
}).toThrowError();
1043+
}).toThrow();
10441044
expect(() => {
10451045
// @ts-expect-error
10461046
state.map.clear();
1047-
}).toThrowError();
1047+
}).toThrow();
10481048
});
10491049
});
10501050

@@ -1104,7 +1104,7 @@ describe('hook in options', () => {
11041104
},
11051105
}
11061106
);
1107-
}).toThrowError(/Unsupported mark result/);
1107+
}).toThrow(/Unsupported mark result/);
11081108
});
11091109

11101110
test('only mutable object', () => {
@@ -1869,7 +1869,7 @@ describe('error', () => {
18691869
create(data, (draft) => {
18701870
Object.defineProperty(draft, 'foo', {});
18711871
});
1872-
}).toThrowError(`Cannot call 'defineProperty()' on drafts`);
1872+
}).toThrow(`Cannot call 'defineProperty()' on drafts`);
18731873
});
18741874

18751875
test('not support: setPrototypeOf', () => {
@@ -1879,7 +1879,7 @@ describe('error', () => {
18791879
create(data, (draft) => {
18801880
Object.setPrototypeOf(draft, {});
18811881
});
1882-
}).toThrowError(`Cannot call 'setPrototypeOf()' on drafts`);
1882+
}).toThrow(`Cannot call 'setPrototypeOf()' on drafts`);
18831883
});
18841884
});
18851885

@@ -2016,7 +2016,7 @@ test('enablePatches and changes', () => {
20162016
enablePatches: true,
20172017
}
20182018
);
2019-
}).not.toThrowError();
2019+
}).not.toThrow();
20202020
});
20212021

20222022
test(`Don't auto freeze non-enumerable or symbolic properties`, () => {

test/curry.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('Currying', () => {
3535
expect(() => {
3636
// @ts-expect-error
3737
state.foobar.bar = 'new baz';
38-
}).toThrowError();
38+
}).toThrow();
3939
});
4040

4141
test('Currying with enablePatches', () => {
@@ -92,7 +92,7 @@ describe('Currying', () => {
9292
expect(() => {
9393
// @ts-expect-error
9494
state.foobar.bar = 'new baz';
95-
}).toThrowError();
95+
}).toThrow();
9696
});
9797

9898
test('Currying with undraftable state', () => {
@@ -190,7 +190,7 @@ describe('Currying', () => {
190190

191191
test('Currying a draft', () => {
192192
create({ a: 1 }, (draft) => {
193-
expect(() => create(draft)).not.toThrowError();
193+
expect(() => create(draft)).not.toThrow();
194194
});
195195
});
196196

@@ -502,7 +502,7 @@ test(`check Primitive type`, () => {
502502
new WeakMap(),
503503
new WeakSet(),
504504
].forEach((value: any) => {
505-
expect(() => create(value)).toThrowError();
505+
expect(() => create(value)).toThrow();
506506
});
507507
});
508508

@@ -527,6 +527,6 @@ test(`check Primitive type with patches`, () => {
527527
new WeakMap(),
528528
new WeakSet(),
529529
].forEach((value: any) => {
530-
expect(() => create(value, { enablePatches: true })).toThrowError();
530+
expect(() => create(value, { enablePatches: true })).toThrow();
531531
});
532532
});

test/dev.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test('custom shallow copy without checking in prod mode', () => {
2323
},
2424
}
2525
);
26-
}).not.toThrowError();
26+
}).not.toThrow();
2727

2828
expect(() => {
2929
create(
@@ -41,7 +41,7 @@ test('custom shallow copy without checking in prod mode', () => {
4141
},
4242
}
4343
);
44-
}).not.toThrowError();
44+
}).not.toThrow();
4545
});
4646

4747
test('custom shallow copy with checking in dev mode', () => {

test/immer-non-support.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ test('Unexpected operation check of Set draft', () => {
7171
// @ts-ignore
7272
draft.x = 1;
7373
});
74-
}).not.toThrowError();
74+
}).not.toThrow();
7575
}
7676
{
7777
const data = new Set([1]);
@@ -80,7 +80,7 @@ test('Unexpected operation check of Set draft', () => {
8080
// @ts-ignore
8181
draft.x = 1;
8282
});
83-
}).toThrowError(`Map/Set draft does not support any property assignment.`);
83+
}).toThrow(`Map/Set draft does not support any property assignment.`);
8484
}
8585
});
8686

@@ -94,7 +94,7 @@ test('Unexpected operation check of Map draft', () => {
9494
// @ts-ignore
9595
draft.x = 1;
9696
});
97-
}).not.toThrowError();
97+
}).not.toThrow();
9898
}
9999

100100
{
@@ -104,7 +104,7 @@ test('Unexpected operation check of Map draft', () => {
104104
// @ts-ignore
105105
draft.x = 1;
106106
});
107-
}).toThrowError(`Map/Set draft does not support any property assignment.`);
107+
}).toThrow(`Map/Set draft does not support any property assignment.`);
108108
}
109109
});
110110

@@ -123,7 +123,7 @@ test('immer failed case - freeze Map key', () => {
123123
expect(() => {
124124
// @ts-ignore
125125
Array.from(state.keys())[0].a = 2;
126-
}).not.toThrowError();
126+
}).not.toThrow();
127127
}
128128

129129
{
@@ -141,7 +141,7 @@ test('immer failed case - freeze Map key', () => {
141141
expect(() => {
142142
// @ts-ignore
143143
Array.from(state.keys())[0].a = 2;
144-
}).toThrowError();
144+
}).toThrow();
145145
}
146146
});
147147

@@ -165,7 +165,7 @@ test('immer failed case - escaped draft', () => {
165165

166166
expect(() => {
167167
JSON.stringify(state);
168-
}).toThrowError();
168+
}).toThrow();
169169
}
170170

171171
{
@@ -186,7 +186,7 @@ test('immer failed case - escaped draft', () => {
186186

187187
expect(() => {
188188
JSON.stringify(state);
189-
}).not.toThrowError();
189+
}).not.toThrow();
190190
}
191191
});
192192

@@ -270,7 +270,7 @@ test('circular reference', () => {
270270
produce(data, () => {
271271
//
272272
});
273-
}).not.toThrowError();
273+
}).not.toThrow();
274274
}
275275

276276
{
@@ -350,10 +350,10 @@ test('#18 - set: assigning a non-draft with the same key - 1', () => {
350350
// @ts-ignore
351351
// eslint-disable-next-line no-unused-expressions
352352
Array.from(produced[0].array[0].one)[0].three;
353-
}).toThrowError();
353+
}).toThrow();
354354

355355
// @ts-ignore
356-
expect(() => applyPatches(baseState, produced[1])).toThrowError();
356+
expect(() => applyPatches(baseState, produced[1])).toThrow();
357357
// @ts-ignore
358358
expect(applyPatches(produced[0], produced[2])).toEqual(baseState);
359359
}
@@ -372,7 +372,7 @@ test('#18 - set: assigning a non-draft with the same key - 2', () => {
372372
draft.c = new Set([draft.c[0], f]);
373373
});
374374
// @ts-ignore
375-
expect(() => applyPatches(baseState, produced[1])).toThrowError();
375+
expect(() => applyPatches(baseState, produced[1])).toThrow();
376376
// @ts-ignore
377377
expect(applyPatches(produced[0], produced[2])).toEqual(baseState);
378378
}
@@ -460,7 +460,7 @@ test('produce leaks proxy objects when symbols are present', () => {
460460
// @ts-ignore
461461
draft.child.count++;
462462
});
463-
}).toThrowError();
463+
}).toThrow();
464464
}
465465
{
466466
const Parent = Symbol();
@@ -481,7 +481,7 @@ test('produce leaks proxy objects when symbols are present', () => {
481481
// @ts-ignore
482482
draft.child.count++;
483483
});
484-
}).not.toThrowError();
484+
}).not.toThrow();
485485
}
486486
});
487487

@@ -494,7 +494,7 @@ test('error key setting in array', () => {
494494
// @ts-ignore
495495
draft[key] = 'new str';
496496
});
497-
}).not.toThrowError();
497+
}).not.toThrow();
498498
}
499499
}
500500
{

0 commit comments

Comments
 (0)