Skip to content

Commit

Permalink
Use createRoot in useFocus-test (#28083)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpope authored Jan 25, 2024
1 parent b123b9c commit a41ebfc
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {createEventTarget, setPointerEvent} from 'dom-event-testing-library';

let React;
let ReactFeatureFlags;
let ReactDOM;
let ReactDOMClient;
let useFocus;
let act;

Expand All @@ -23,7 +23,7 @@ function initializeModules(hasPointerEvents) {
ReactFeatureFlags = require('shared/ReactFeatureFlags');
ReactFeatureFlags.enableCreateEventHandleAPI = true;
React = require('react');
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom/client');
act = require('internal-test-utils').act;
// TODO: This import throws outside of experimental mode. Figure out better
// strategy for gated imports.
Expand All @@ -45,7 +45,6 @@ describe.each(table)(`useFocus hasPointerEvents=%s`, hasPointerEvents => {
});

afterEach(() => {
ReactDOM.render(null, container);
document.body.removeChild(container);
container = null;
});
Expand All @@ -65,8 +64,9 @@ describe.each(table)(`useFocus hasPointerEvents=%s`, hasPointerEvents => {
});
return <div ref={ref} />;
};
const root = ReactDOMClient.createRoot(container);
await act(() => {
ReactDOM.render(<Component />, container);
root.render(<Component />);
});
};

Expand All @@ -93,8 +93,9 @@ describe.each(table)(`useFocus hasPointerEvents=%s`, hasPointerEvents => {
});
return <div ref={ref} />;
};
const root = ReactDOMClient.createRoot(container);
await act(() => {
ReactDOM.render(<Component />, container);
root.render(<Component />);
});
};

Expand Down Expand Up @@ -125,8 +126,9 @@ describe.each(table)(`useFocus hasPointerEvents=%s`, hasPointerEvents => {
</div>
);
};
const root = ReactDOMClient.createRoot(container);
await act(() => {
ReactDOM.render(<Component />, container);
root.render(<Component />);
});
};

Expand Down Expand Up @@ -164,8 +166,9 @@ describe.each(table)(`useFocus hasPointerEvents=%s`, hasPointerEvents => {
</div>
);
};
const root = ReactDOMClient.createRoot(container);
await act(() => {
ReactDOM.render(<Component />, container);
root.render(<Component />);
});
};

Expand Down Expand Up @@ -209,8 +212,9 @@ describe.each(table)(`useFocus hasPointerEvents=%s`, hasPointerEvents => {
</div>
);
};
const root = ReactDOMClient.createRoot(container);
await act(() => {
ReactDOM.render(<Component />, container);
root.render(<Component />);
});
};

Expand Down Expand Up @@ -305,8 +309,9 @@ describe.each(table)(`useFocus hasPointerEvents=%s`, hasPointerEvents => {
);
};

const root = ReactDOMClient.createRoot(container);
await act(() => {
ReactDOM.render(<Outer />, container);
root.render(<Outer />);
});
const innerTarget = createEventTarget(innerRef.current);
const outerTarget = createEventTarget(outerRef.current);
Expand Down

0 comments on commit a41ebfc

Please sign in to comment.