Skip to content

Commit fbbcc1d

Browse files
author
Andrew Luca
authored
test: enable React.StrictMode (#593)
https://reactjs.org/docs/strict-mode.html Introduced in `react@16.3` which is minimal version that is supported https://reactjs.org/blog/2018/03/29/react-v-16-3.html
1 parent c863158 commit fbbcc1d

File tree

2 files changed

+37
-24
lines changed

2 files changed

+37
-24
lines changed

test/CSSTransitionGroup-test.js

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ let TransitionGroup;
1010
describe('CSSTransitionGroup', () => {
1111
let container;
1212
let consoleErrorSpy;
13+
let render;
1314

1415
function YoloTransition({ id, ...props }) {
1516
const nodeRef = React.useRef()
@@ -27,6 +28,12 @@ describe('CSSTransitionGroup', () => {
2728
React = require('react');
2829
ReactDOM = require('react-dom');
2930

31+
render = (element, container, callback) => ReactDOM.render(
32+
<React.StrictMode>{element}</React.StrictMode>,
33+
container,
34+
callback
35+
)
36+
3037
TransitionGroup = require('../src/TransitionGroup');
3138

3239
container = document.createElement('div');
@@ -39,7 +46,7 @@ describe('CSSTransitionGroup', () => {
3946

4047

4148
it('should clean-up silently after the timeout elapses', () => {
42-
ReactDOM.render(
49+
render(
4350
<TransitionGroup enter={false}>
4451
<YoloTransition key="one" id="one"/>
4552
</TransitionGroup>,
@@ -50,7 +57,7 @@ describe('CSSTransitionGroup', () => {
5057

5158
expect(transitionGroupDiv.childNodes.length).toBe(1);
5259

53-
ReactDOM.render(
60+
render(
5461
<TransitionGroup enter={false}>
5562
<YoloTransition key="two" id="two"/>
5663
</TransitionGroup>,
@@ -72,7 +79,7 @@ describe('CSSTransitionGroup', () => {
7279
});
7380

7481
it('should keep both sets of DOM nodes around', () => {
75-
ReactDOM.render(
82+
render(
7683
<TransitionGroup>
7784
<YoloTransition key="one" id="one" />
7885
</TransitionGroup>,
@@ -83,7 +90,7 @@ describe('CSSTransitionGroup', () => {
8390

8491
expect(transitionGroupDiv.childNodes.length).toBe(1);
8592

86-
ReactDOM.render(
93+
render(
8794
<TransitionGroup>
8895
<YoloTransition key="two" id="two" />
8996
</TransitionGroup>,
@@ -96,7 +103,7 @@ describe('CSSTransitionGroup', () => {
96103
});
97104

98105
it('should switch transitionLeave from false to true', () => {
99-
ReactDOM.render(
106+
render(
100107
<TransitionGroup enter={false} leave={false}>
101108
<YoloTransition key="one" id="one" />
102109
</TransitionGroup>,
@@ -107,7 +114,7 @@ describe('CSSTransitionGroup', () => {
107114

108115
expect(transitionGroupDiv.childNodes.length).toBe(1);
109116

110-
ReactDOM.render(
117+
render(
111118
<TransitionGroup enter={false} leave={false}>
112119
<YoloTransition key="two" id="two" />
113120
</TransitionGroup>,
@@ -118,7 +125,7 @@ describe('CSSTransitionGroup', () => {
118125

119126
expect(transitionGroupDiv.childNodes.length).toBe(1);
120127

121-
ReactDOM.render(
128+
render(
122129
<TransitionGroup enter={false} leave>
123130
<YoloTransition key="three" id="three" />
124131
</TransitionGroup>,
@@ -132,7 +139,7 @@ describe('CSSTransitionGroup', () => {
132139

133140

134141
it('should work with a null child', () => {
135-
ReactDOM.render(
142+
render(
136143
<TransitionGroup>
137144
{[null]}
138145
</TransitionGroup>,
@@ -144,26 +151,26 @@ describe('CSSTransitionGroup', () => {
144151
const NullComponent = () => null;
145152
// Testing the whole lifecycle of entering and exiting,
146153
// because those lifecycle methods used to fail when the DOM node was null.
147-
ReactDOM.render(
154+
render(
148155
<TransitionGroup/>,
149156
container,
150157
);
151-
ReactDOM.render(
158+
render(
152159
<TransitionGroup>
153160
<CSSTransition classNames="yolo" timeout={0}>
154161
<NullComponent/>
155162
</CSSTransition>
156163
</TransitionGroup>,
157164
container,
158165
);
159-
ReactDOM.render(
166+
render(
160167
<TransitionGroup/>,
161168
container,
162169
);
163170
});
164171

165172
it('should transition from one to null', () => {
166-
ReactDOM.render(
173+
render(
167174
<TransitionGroup>
168175
<YoloTransition key="one" id="one" />
169176
</TransitionGroup>,
@@ -174,7 +181,7 @@ describe('CSSTransitionGroup', () => {
174181

175182
expect(transitionGroupDiv.childNodes.length).toBe(1);
176183

177-
ReactDOM.render(
184+
render(
178185
<TransitionGroup>
179186
{null}
180187
</TransitionGroup>,
@@ -188,7 +195,7 @@ describe('CSSTransitionGroup', () => {
188195
});
189196

190197
it('should transition from false to one', () => {
191-
ReactDOM.render(
198+
render(
192199
<TransitionGroup>
193200
{false}
194201
</TransitionGroup>,
@@ -199,7 +206,7 @@ describe('CSSTransitionGroup', () => {
199206

200207
expect(transitionGroupDiv.childNodes.length).toBe(0);
201208

202-
ReactDOM.render(
209+
render(
203210
<TransitionGroup>
204211
<YoloTransition key="one" id="one" />
205212
</TransitionGroup>,
@@ -221,8 +228,8 @@ describe('CSSTransitionGroup', () => {
221228
}
222229
}
223230

224-
ReactDOM.render(<Component />, container);
225-
ReactDOM.render(
231+
render(<Component />, container);
232+
render(
226233
<Component>
227234
<YoloTransition key="yolo" id="yolo" />
228235
</Component>,
@@ -259,7 +266,7 @@ describe('CSSTransitionGroup', () => {
259266
}
260267
}
261268

262-
ReactDOM.render(<Component />, container);
269+
render(<Component />, container);
263270

264271
// Testing that no exception is thrown here, as the timeout has been cleared.
265272
jest.runAllTimers();
@@ -298,7 +305,7 @@ describe('CSSTransitionGroup', () => {
298305
}
299306
}
300307

301-
ReactDOM.render(<Component />, container);
308+
render(<Component />, container);
302309
const transitionGroupDiv = container.childNodes[0]
303310
transitionGroupDiv.childNodes.forEach(child => {
304311
expect(hasClass(child, extraClassNameProp)).toBe(true);

test/TransitionGroup-test.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,20 @@ let Transition
88
// Most of the real functionality is covered in other unit tests, this just
99
// makes sure we're wired up correctly.
1010
describe('TransitionGroup', () => {
11-
let container, log, Child
11+
let container, log, Child, render;
1212

1313
beforeEach(() => {
1414
React = require('react')
1515
ReactDOM = require('react-dom')
1616
Transition = require('../src/Transition').default
1717
TransitionGroup = require('../src/TransitionGroup')
1818

19+
render = (element, container, callback) => ReactDOM.render(
20+
<React.StrictMode>{element}</React.StrictMode>,
21+
container,
22+
callback
23+
)
24+
1925
container = document.createElement('div')
2026

2127
log = []
@@ -70,7 +76,7 @@ describe('TransitionGroup', () => {
7076
})
7177

7278
it('should work with no children', () => {
73-
ReactDOM.render(<TransitionGroup />, container)
79+
render(<TransitionGroup />, container)
7480
})
7581

7682
it('should handle transitioning correctly', () => {
@@ -85,18 +91,18 @@ describe('TransitionGroup', () => {
8591
}
8692

8793
jest.useFakeTimers()
88-
ReactDOM.render(<Parent />, container)
94+
render(<Parent />, container)
8995

9096
jest.runAllTimers()
9197
expect(log).toEqual(['appear', 'appearing', 'appeared'])
9298

9399
log = []
94-
ReactDOM.render(<Parent count={2} />, container)
100+
render(<Parent count={2} />, container)
95101
jest.runAllTimers()
96102
expect(log).toEqual(['enter', 'entering', 'entered'])
97103

98104
log = []
99-
ReactDOM.render(<Parent count={1} />, container)
105+
render(<Parent count={1} />, container)
100106
jest.runAllTimers()
101107
expect(log).toEqual(['exit', 'exiting', 'exited'])
102108
})

0 commit comments

Comments
 (0)