1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  3.  *
    
  4.  * This source code is licensed under the MIT license found in the
    
  5.  * LICENSE file in the root directory of this source tree.
    
  6.  *
    
  7.  * @emails react-core
    
  8.  * @jest-environment node
    
  9.  */
    
  10. 
    
  11. 'use strict';
    
  12. 
    
  13. let React;
    
  14. let act;
    
  15. let ReactFiberReconciler;
    
  16. let ConcurrentRoot;
    
  17. let DefaultEventPriority;
    
  18. 
    
  19. describe('ReactFiberHostContext', () => {
    
  20.   beforeEach(() => {
    
  21.     jest.resetModules();
    
  22.     React = require('react');
    
  23.     act = React.unstable_act;
    
  24.     ReactFiberReconciler = require('react-reconciler');
    
  25.     ConcurrentRoot =
    
  26.       require('react-reconciler/src/ReactRootTags').ConcurrentRoot;
    
  27.     DefaultEventPriority =
    
  28.       require('react-reconciler/src/ReactEventPriorities').DefaultEventPriority;
    
  29.   });
    
  30. 
    
  31.   global.IS_REACT_ACT_ENVIRONMENT = true;
    
  32. 
    
  33.   // @gate __DEV__
    
  34.   it('should send the context to prepareForCommit and resetAfterCommit', () => {
    
  35.     const rootContext = {};
    
  36.     const childContext = {};
    
  37.     const Renderer = ReactFiberReconciler({
    
  38.       prepareForCommit: function (hostContext) {
    
  39.         expect(hostContext).toBe(rootContext);
    
  40.         return null;
    
  41.       },
    
  42.       resetAfterCommit: function (hostContext) {
    
  43.         expect(hostContext).toBe(rootContext);
    
  44.       },
    
  45.       getRootHostContext: function () {
    
  46.         return rootContext;
    
  47.       },
    
  48.       getChildHostContext: function () {
    
  49.         return childContext;
    
  50.       },
    
  51.       shouldSetTextContent: function () {
    
  52.         return false;
    
  53.       },
    
  54.       createInstance: function () {
    
  55.         return null;
    
  56.       },
    
  57.       finalizeInitialChildren: function () {
    
  58.         return null;
    
  59.       },
    
  60.       appendInitialChild: function () {
    
  61.         return null;
    
  62.       },
    
  63.       now: function () {
    
  64.         return 0;
    
  65.       },
    
  66.       appendChildToContainer: function () {
    
  67.         return null;
    
  68.       },
    
  69.       clearContainer: function () {},
    
  70.       getCurrentEventPriority: function () {
    
  71.         return DefaultEventPriority;
    
  72.       },
    
  73.       shouldAttemptEagerTransition() {
    
  74.         return false;
    
  75.       },
    
  76.       requestPostPaintCallback: function () {},
    
  77.       maySuspendCommit(type, props) {
    
  78.         return false;
    
  79.       },
    
  80.       preloadInstance(type, props) {
    
  81.         return true;
    
  82.       },
    
  83.       startSuspendingCommit() {},
    
  84.       suspendInstance(type, props) {},
    
  85.       waitForCommitToBeReady() {
    
  86.         return null;
    
  87.       },
    
  88.       supportsMutation: true,
    
  89.     });
    
  90. 
    
  91.     const container = Renderer.createContainer(
    
  92.       rootContext,
    
  93.       ConcurrentRoot,
    
  94.       null,
    
  95.       false,
    
  96.       '',
    
  97.       null,
    
  98.     );
    
  99.     act(() => {
    
  100.       Renderer.updateContainer(
    
  101.         <a>
    
  102.           <b />
    
  103.         </a>,
    
  104.         container,
    
  105.         /* parentComponent: */ null,
    
  106.         /* callback: */ null,
    
  107.       );
    
  108.     });
    
  109.   });
    
  110. });