/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @emails react-core */ 'use strict'; const React = require('react'); const ReactDOMClient = require('react-dom/client'); const act = require('internal-test-utils').act; /** * Tests that when a ref hops around children, we can track that correctly. */ describe('ref swapping', () => { let RefHopsAround; beforeEach(() => { RefHopsAround = class extends React.Component { container = null; state = {count: 0}; hopRef = React.createRef(); divOneRef = React.createRef(); divTwoRef = React.createRef(); divThreeRef = React.createRef(); moveRef = () => { this.setState({count: this.state.count + 1}); }; render() { const count = this.state.count; /** * What we have here, is three divs with refs (div1/2/3), but a single * moving cursor ref `hopRef` that "hops" around the three. We'll call the * `moveRef()` function several times and make sure that the hop ref * points to the correct divs. */ return (