Skip to content

Commit ebbd221

Browse files
authored
Configure react-test-renderer as a secondary (#13164)
1 parent ddc91af commit ebbd221

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

packages/react-art/src/__tests__/ReactART-test.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ const Circle = require('react-art/Circle');
2828
const Rectangle = require('react-art/Rectangle');
2929
const Wedge = require('react-art/Wedge');
3030

31+
// Isolate the noop renderer
32+
jest.resetModules();
33+
const ReactNoop = require('react-noop-renderer');
34+
3135
let Group;
3236
let Shape;
3337
let Surface;
@@ -354,7 +358,7 @@ describe('ReactART', () => {
354358
const CurrentRendererContext = React.createContext(null);
355359

356360
function Yield(props) {
357-
testRenderer.unstable_yield(props.value);
361+
ReactNoop.yield(props.value);
358362
return null;
359363
}
360364

@@ -372,19 +376,16 @@ describe('ReactART', () => {
372376

373377
// Using test renderer instead of the DOM renderer here because async
374378
// testing APIs for the DOM renderer don't exist.
375-
const testRenderer = ReactTestRenderer.create(
379+
ReactNoop.render(
376380
<CurrentRendererContext.Provider value="Test">
377381
<Yield value="A" />
378382
<Yield value="B" />
379383
<LogCurrentRenderer />
380384
<Yield value="C" />
381385
</CurrentRendererContext.Provider>,
382-
{
383-
unstable_isAsync: true,
384-
},
385386
);
386387

387-
testRenderer.unstable_flushThrough(['A']);
388+
ReactNoop.flushThrough(['A']);
388389

389390
ReactDOM.render(
390391
<Surface>
@@ -399,7 +400,7 @@ describe('ReactART', () => {
399400
expect(ops).toEqual([null, 'ART']);
400401

401402
ops = [];
402-
expect(testRenderer.unstable_flushAll()).toEqual(['B', 'C']);
403+
expect(ReactNoop.flush()).toEqual(['B', 'C']);
403404

404405
expect(ops).toEqual(['Test']);
405406
});

packages/react-test-renderer/src/ReactTestHostConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export function createTextInstance(
180180
};
181181
}
182182

183-
export const isPrimaryRenderer = true;
183+
export const isPrimaryRenderer = false;
184184
// This approach enables `now` to be mocked by tests,
185185
// Even after the reconciler has initialized and read host config values.
186186
export const now = () => TestRendererScheduling.nowImplementation();

packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.internal.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ const React = require('react');
1616
const ReactTestRenderer = require('react-test-renderer');
1717
const prettyFormat = require('pretty-format');
1818

19+
// Isolate noop renderer
20+
jest.resetModules();
21+
const ReactNoop = require('react-noop-renderer');
22+
1923
// Kind of hacky, but we nullify all the instances to test the tree structure
2024
// with jasmine's deep equality function, and test the instances separate. We
2125
// also delete children props because testing them is more annoying and not
@@ -1000,4 +1004,19 @@ describe('ReactTestRenderer', () => {
10001004
}),
10011005
);
10021006
});
1007+
1008+
it('can concurrently render context with a "primary" renderer', () => {
1009+
const Context = React.createContext(null);
1010+
const Indirection = React.Fragment;
1011+
const App = () => (
1012+
<Context.Provider>
1013+
<Indirection>
1014+
<Context.Consumer>{() => null}</Context.Consumer>
1015+
</Indirection>
1016+
</Context.Provider>
1017+
);
1018+
ReactNoop.render(<App />);
1019+
ReactNoop.flush();
1020+
ReactTestRenderer.create(<App />);
1021+
});
10031022
});

0 commit comments

Comments
 (0)