Skip to content

Commit b7856ae

Browse files
committed
Use gate pragma in ReacetOffscreenStrictMode test
1 parent bedfe3d commit b7856ae

File tree

2 files changed

+42
-69
lines changed

2 files changed

+42
-69
lines changed

packages/react-reconciler/src/__tests__/ReactOffscreenStrictMode-test.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ describe('ReactOffscreenStrictMode', () => {
1313
Offscreen = React.unstable_Offscreen;
1414
ReactNoop = require('react-noop-renderer');
1515
act = require('jest-react').act;
16-
17-
const ReactFeatureFlags = require('shared/ReactFeatureFlags');
18-
ReactFeatureFlags.enableStrictEffects = __DEV__;
19-
ReactFeatureFlags.createRootStrictEffectsByDefault = __DEV__;
2016
});
2117

2218
function Component({label}) {
@@ -35,14 +31,15 @@ describe('ReactOffscreenStrictMode', () => {
3531
return <span>label</span>;
3632
}
3733

38-
// @gate enableOffscreen
39-
// @gate __DEV__
34+
// @gate __DEV__ && enableStrictEffects && enableOffscreen
4035
it('should trigger strict effects when offscreen is visible', () => {
4136
act(() => {
4237
ReactNoop.render(
43-
<Offscreen mode="visible">
44-
<Component label="A" />
45-
</Offscreen>,
38+
<React.StrictMode>
39+
<Offscreen mode="visible">
40+
<Component label="A" />
41+
</Offscreen>
42+
</React.StrictMode>,
4643
);
4744
});
4845

@@ -58,14 +55,15 @@ describe('ReactOffscreenStrictMode', () => {
5855
]);
5956
});
6057

61-
// @gate enableOffscreen
62-
// @gate __DEV__
58+
// @gate __DEV__ && enableStrictEffects && enableOffscreen
6359
it('should not trigger strict effects when offscreen is hidden', () => {
6460
act(() => {
6561
ReactNoop.render(
66-
<Offscreen mode="hidden">
67-
<Component label="A" />
68-
</Offscreen>,
62+
<React.StrictMode>
63+
<Offscreen mode="hidden">
64+
<Component label="A" />
65+
</Offscreen>
66+
</React.StrictMode>,
6967
);
7068
});
7169

@@ -75,9 +73,11 @@ describe('ReactOffscreenStrictMode', () => {
7573

7674
act(() => {
7775
ReactNoop.render(
78-
<Offscreen mode="visible">
79-
<Component label="A" />
80-
</Offscreen>,
76+
<React.StrictMode>
77+
<Offscreen mode="visible">
78+
<Component label="A" />
79+
</Offscreen>
80+
</React.StrictMode>,
8181
);
8282
});
8383

packages/react/src/__tests__/ReactStrictMode-test.js

Lines changed: 25 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('ReactStrictMode', () => {
6767
);
6868
});
6969

70-
// @gate enableStrictEffects
70+
// @gate __DEV__
7171
it('should invoke precommit lifecycle methods twice', () => {
7272
let log = [];
7373
let shouldComponentUpdate = false;
@@ -108,26 +108,15 @@ describe('ReactStrictMode', () => {
108108
container,
109109
);
110110

111-
if (__DEV__) {
112-
expect(log).toEqual([
113-
'constructor',
114-
'constructor',
115-
'getDerivedStateFromProps',
116-
'getDerivedStateFromProps',
117-
'render',
118-
'render',
119-
'componentDidMount',
120-
'componentWillUnmount',
121-
'componentDidMount',
122-
]);
123-
} else {
124-
expect(log).toEqual([
125-
'constructor',
126-
'getDerivedStateFromProps',
127-
'render',
128-
'componentDidMount',
129-
]);
130-
}
111+
expect(log).toEqual([
112+
'constructor',
113+
'constructor',
114+
'getDerivedStateFromProps',
115+
'getDerivedStateFromProps',
116+
'render',
117+
'render',
118+
'componentDidMount',
119+
]);
131120

132121
log = [];
133122
shouldComponentUpdate = true;
@@ -138,24 +127,15 @@ describe('ReactStrictMode', () => {
138127
</React.StrictMode>,
139128
container,
140129
);
141-
if (__DEV__) {
142-
expect(log).toEqual([
143-
'getDerivedStateFromProps',
144-
'getDerivedStateFromProps',
145-
'shouldComponentUpdate',
146-
'shouldComponentUpdate',
147-
'render',
148-
'render',
149-
'componentDidUpdate',
150-
]);
151-
} else {
152-
expect(log).toEqual([
153-
'getDerivedStateFromProps',
154-
'shouldComponentUpdate',
155-
'render',
156-
'componentDidUpdate',
157-
]);
158-
}
130+
expect(log).toEqual([
131+
'getDerivedStateFromProps',
132+
'getDerivedStateFromProps',
133+
'shouldComponentUpdate',
134+
'shouldComponentUpdate',
135+
'render',
136+
'render',
137+
'componentDidUpdate',
138+
]);
159139

160140
log = [];
161141
shouldComponentUpdate = false;
@@ -167,19 +147,12 @@ describe('ReactStrictMode', () => {
167147
container,
168148
);
169149

170-
if (__DEV__) {
171-
expect(log).toEqual([
172-
'getDerivedStateFromProps',
173-
'getDerivedStateFromProps',
174-
'shouldComponentUpdate',
175-
'shouldComponentUpdate',
176-
]);
177-
} else {
178-
expect(log).toEqual([
179-
'getDerivedStateFromProps',
180-
'shouldComponentUpdate',
181-
]);
182-
}
150+
expect(log).toEqual([
151+
'getDerivedStateFromProps',
152+
'getDerivedStateFromProps',
153+
'shouldComponentUpdate',
154+
'shouldComponentUpdate',
155+
]);
183156
});
184157

185158
it('should invoke setState callbacks twice', () => {

0 commit comments

Comments
 (0)