Skip to content

Commit

Permalink
Use RN global to maintain legacy root behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack Pope committed Mar 25, 2024
1 parent 72fb32a commit ca324ab
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/react-test-renderer/src/ReactTestRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,15 +483,18 @@ function create(
}

let createNodeMock = defaultTestOptions.createNodeMock;
let isConcurrent = true;
const isConcurrentOnly =
disableLegacyMode === true &&
global.IS_REACT_NATIVE_TEST_ENVIRONMENT !== true;
let isConcurrent = isConcurrentOnly;
let isStrictMode = false;
let concurrentUpdatesByDefault = null;
if (typeof options === 'object' && options !== null) {
if (typeof options.createNodeMock === 'function') {
// $FlowFixMe[incompatible-type] found when upgrading Flow
createNodeMock = options.createNodeMock;
}
if (disableLegacyMode === false) {
if (!isConcurrentOnly) {
isConcurrent = options.unstable_isConcurrent;
}
if (options.unstable_strictMode === true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ const {format: prettyFormat} = require('pretty-format');
const InternalTestUtils = require('internal-test-utils');
const waitForAll = InternalTestUtils.waitForAll;
const act = InternalTestUtils.act;
const Reconciler = require('react-reconciler/src/ReactFiberReconciler');
const {
ConcurrentRoot,
LegacyRoot,
} = require('react-reconciler/src/ReactRootTags');

// Isolate noop renderer
jest.resetModules();
Expand Down Expand Up @@ -65,6 +70,53 @@ describe('ReactTestRenderer', () => {
);
});

describe('root tags', () => {
let createContainerSpy;
beforeEach(() => {
createContainerSpy = jest.spyOn(Reconciler, 'createContainer');
});

function expectTag(tag) {
expect(createContainerSpy).toHaveBeenCalledWith(
expect.anything(),
tag,
null,
expect.anything(),
null,
expect.anything(),
expect.anything(),
null,
);
}

// @gate disableLegacyMode
it('should render using concurrent root if disableLegacyMode', () => {
ReactTestRenderer.create(<div />);
expectTag(ConcurrentRoot);
});

// @gate !disableLegacyMode
it('should default to legacy root if not disableLegacyMode', () => {
ReactTestRenderer.create(<div />);
expectTag(LegacyRoot);
});

it('should allow unstable_isConcurrent if not disableLegacyMode', async () => {
ReactTestRenderer.create(<div />, {
unstable_isConcurrent: true,
});
ReactTestRenderer.create(<div />);
expectTag(ConcurrentRoot);
});

it('should render legacy root when RN test environment', async () => {
global.IS_REACT_NATIVE_TEST_ENVIRONMENT = true;
ReactTestRenderer.create(<div />);
expectTag(LegacyRoot);
global.IS_REACT_NATIVE_TEST_ENVIRONMENT = false;
});
});

it('renders a simple component', async () => {
function Link() {
return <a role="link" />;
Expand Down

0 comments on commit ca324ab

Please sign in to comment.