Repository: facebook/react
File: packages/react-reconciler/src/__tests__/ReactScope-test.internal.js (JavaScript)

Code before:
      // This should not cause a runtime exception, see:
      // https://github.com/facebook/react/pull/18184
      scopeRef.current.DO_NOT_USE_queryAllNodes(testScopeQuery);
      expect(ref.current).toBe(null);

      // Resolving the promise should continue hydration
      suspend = false;
      await act(async () => {
        resolve();
        await promise;
      });

      // We should now have hydrated with a ref on the existing span.
      expect(ref.current).toBe(span);
    });
  });

  describe('ReactTestRenderer', () => {
    let ReactTestRenderer;

    beforeEach(() => {
      ReactTestRenderer = require('react-test-renderer');
    });

    // @gate www
    // @gate !disableLegacyMode
    it('DO_NOT_USE_queryAllNodes() works as intended', () => {
      const testScopeQuery = (type, props) => true;
      const TestScope = React.unstable_Scope;
      const scopeRef = React.createRef();
      const divRef = React.createRef();
      const spanRef = React.createRef();
      const aRef = React.createRef();

      function Test({toggle}) {
        return toggle ? (
          <TestScope ref={scopeRef}>
            <div ref={divRef}>DIV</div>
            <span ref={spanRef}>SPAN</span>
            <a ref={aRef}>A</a>
          </TestScope>
        ) : (
          <TestScope ref={scopeRef}>
            <a ref={aRef}>A</a>
            <div ref={divRef}>DIV</div>
            <span ref={spanRef}>SPAN</span>
          </TestScope>
        );
      }

      const renderer = ReactTestRenderer.create(<Test toggle={true} />, {

Review comment (bug):
these tests fail when legacy mode is disabled. I am guessing these tests would actually fail if the root was a concurrent root at all and when legacy mode is disabled the test renderer always runs in concurrent mode. Since this is legacy feature that won't be stabilized I decided to turn the tests off when legacy mode is removed

Code after:
      // This should not cause a runtime exception, see:
      // https://github.com/facebook/react/pull/18184
      scopeRef.current.DO_NOT_USE_queryAllNodes(testScopeQuery);
      expect(ref.current).toBe(null);

      // Resolving the promise should continue hydration
      suspend = false;
      await act(async () => {
        resolve();
        await promise;
      });

      // We should now have hydrated with a ref on the existing span.
      expect(ref.current).toBe(span);
    });
  });

  describe('ReactTestRenderer', () => {
    let ReactTestRenderer;

    beforeEach(() => {
      ReactTestRenderer = require('react-test-renderer');
    });

    // @gate www
    it('DO_NOT_USE_queryAllNodes() works as intended', async () => {
      const testScopeQuery = (type, props) => true;
      const TestScope = React.unstable_Scope;
      const scopeRef = React.createRef();
      const divRef = React.createRef();
      const spanRef = React.createRef();
      const aRef = React.createRef();

      function Test({toggle}) {
        return toggle ? (
          <TestScope ref={scopeRef}>
            <div ref={divRef}>DIV</div>
            <span ref={spanRef}>SPAN</span>
            <a ref={aRef}>A</a>
          </TestScope>
        ) : (
          <TestScope ref={scopeRef}>
            <a ref={aRef}>A</a>
            <div ref={divRef}>DIV</div>
            <span ref={spanRef}>SPAN</span>
          </TestScope>
        );
      }

      let renderer;
      await act(