Skip to content

Commit 43640f3

Browse files
committed
test(dev): add testing in prod mode
1 parent 7d1fd1e commit 43640f3

File tree

2 files changed

+70
-44
lines changed

2 files changed

+70
-44
lines changed

test/dev.test.ts

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,10 @@
33
/* eslint-disable @typescript-eslint/ban-ts-comment */
44
import { apply, create } from '../src';
55

6-
test('custom shallow copy without checking in prod mode', () => {
7-
global.__DEV__ = false;
8-
const baseState = { foo: { bar: 'test' } };
9-
10-
expect(() => {
11-
create(
12-
baseState,
13-
(draft) => {
14-
draft.foo.bar = 'test2';
15-
},
16-
{
17-
enableAutoFreeze: true,
18-
// @ts-expect-error
19-
mark: (target) => {
20-
if (target === baseState.foo) {
21-
return () => ({ ...target });
22-
}
23-
},
24-
}
25-
);
26-
}).not.toThrow();
27-
28-
expect(() => {
29-
create(
30-
baseState,
31-
(draft) => {
32-
draft.foo.bar = 'test2';
33-
},
34-
{
35-
enablePatches: true,
36-
// @ts-expect-error
37-
mark: (target) => {
38-
if (target === baseState.foo) {
39-
return () => ({ ...target });
40-
}
41-
},
42-
}
43-
);
44-
}).not.toThrow();
45-
});
6+
global.__DEV__ = true;
467

478
test('custom shallow copy with checking in dev mode', () => {
48-
global.__DEV__ = true;
499
const baseState = { foo: { bar: 'test' } };
50-
5110
expect(() => {
5211
create(
5312
baseState,
@@ -91,7 +50,6 @@ test('custom shallow copy with checking in dev mode', () => {
9150

9251
test('check warn when apply patches with other options', () => {
9352
{
94-
global.__DEV__ = true;
9553
const baseState = { foo: { bar: 'test' } };
9654
const warn = console.warn;
9755
jest.spyOn(console, 'warn').mockImplementation(() => {});
@@ -114,7 +72,6 @@ test('check warn when apply patches with other options', () => {
11472
);
11573
}
11674
{
117-
global.__DEV__ = true;
11875
const baseState = { foo: { bar: 'test' } };
11976
const warn = console.warn;
12077
jest.spyOn(console, 'warn').mockImplementation(() => {});

test/dev1.test.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { apply, create } from '../src';
2+
3+
test('check not warn when apply patches with other options in prod mode', () => {
4+
{
5+
global.__DEV__ = false;
6+
const baseState = { foo: { bar: 'test' } };
7+
const warn = console.warn;
8+
jest.spyOn(console, 'warn').mockImplementation(() => {});
9+
apply(
10+
baseState,
11+
[
12+
{
13+
op: 'replace',
14+
path: ['foo', 'bar'],
15+
value: 'test2',
16+
},
17+
],
18+
{
19+
mutable: true,
20+
enableAutoFreeze: true,
21+
mark: () => {},
22+
}
23+
);
24+
expect(console.warn).not.toHaveBeenCalledWith(
25+
'The "mutable" option is not allowed to be used with other options.'
26+
);
27+
}
28+
});
29+
30+
test('custom shallow copy without checking in prod mode', () => {
31+
global.__DEV__ = false;
32+
const baseState = { foo: { bar: 'test' } };
33+
34+
expect(() => {
35+
create(
36+
baseState,
37+
(draft) => {
38+
draft.foo.bar = 'test2';
39+
},
40+
{
41+
enableAutoFreeze: true,
42+
// @ts-expect-error
43+
mark: (target) => {
44+
if (target === baseState.foo) {
45+
return () => ({ ...target });
46+
}
47+
},
48+
}
49+
);
50+
}).not.toThrow();
51+
52+
expect(() => {
53+
create(
54+
baseState,
55+
(draft) => {
56+
draft.foo.bar = 'test2';
57+
},
58+
{
59+
enablePatches: true,
60+
// @ts-expect-error
61+
mark: (target) => {
62+
if (target === baseState.foo) {
63+
return () => ({ ...target });
64+
}
65+
},
66+
}
67+
);
68+
}).not.toThrow();
69+
});

0 commit comments

Comments
 (0)