| 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 | let NoEventPriority; |
| 19 | |
| 20 | describe('ReactFiberHostContext', () => { |
| 21 | beforeEach(() => { |
| 22 | jest.resetModules(); |
| 23 | React = require('react'); |
| 24 | act = React.act; |
| 25 | ReactFiberReconciler = require('react-reconciler'); |
| 26 | ConcurrentRoot = |
| 27 | require('react-reconciler/src/ReactRootTags').ConcurrentRoot; |
| 28 | DefaultEventPriority = |
| 29 | require('react-reconciler/src/ReactEventPriorities').DefaultEventPriority; |
| 30 | NoEventPriority = |
| 31 | require('react-reconciler/src/ReactEventPriorities').NoEventPriority; |
| 32 | }); |
| 33 | |
| 34 | global.IS_REACT_ACT_ENVIRONMENT = true; |
| 35 | |
| 36 | // @gate __DEV__ |
| 37 | it('should send the context to prepareForCommit and resetAfterCommit', () => { |
| 38 | const rootContext = {}; |
| 39 | const childContext = {}; |
| 40 | let updatePriority: typeof DefaultEventPriority = NoEventPriority; |
| 41 | const Renderer = ReactFiberReconciler({ |
| 42 | prepareForCommit: function (hostContext) { |
| 43 | expect(hostContext).toBe(rootContext); |
| 44 | return null; |
| 45 | }, |
| 46 | resetAfterCommit: function (hostContext) { |
| 47 | expect(hostContext).toBe(rootContext); |
| 48 | }, |
| 49 | getRootHostContext: function () { |
| 50 | return rootContext; |
| 51 | }, |
| 52 | getChildHostContext: function () { |
| 53 | return childContext; |
| 54 | }, |
| 55 | shouldSetTextContent: function () { |
| 56 | return false; |
| 57 | }, |
| 58 | createInstance: function () { |
| 59 | return null; |
| 60 | }, |
| 61 | finalizeInitialChildren: function () { |
| 62 | return null; |
| 63 | }, |
| 64 | appendInitialChild: function () { |
| 65 | return null; |
| 66 | }, |
| 67 | now: function () { |
| 68 | return 0; |
| 69 | }, |
| 70 | appendChildToContainer: function () { |
| 71 | return null; |
| 72 | }, |
| 73 | clearContainer: function () {}, |
| 74 | setCurrentUpdatePriority: function (newPriority: any) { |
| 75 | updatePriority = newPriority; |
| 76 | }, |
| 77 | getCurrentUpdatePriority: function () { |
| 78 | return updatePriority; |
| 79 | }, |
| 80 | resolveUpdatePriority: function () { |
| 81 | if (updatePriority !== NoEventPriority) { |
| 82 | return updatePriority; |
| 83 | } |
| 84 | return DefaultEventPriority; |
| 85 | }, |
| 86 | trackSchedulerEvent: function () {}, |
| 87 | resolveEventType: function () { |
| 88 | return null; |
| 89 | }, |
| 90 | resolveEventTimeStamp: function () { |
| 91 | return -1.1; |
| 92 | }, |
| 93 | shouldAttemptEagerTransition() { |
| 94 | return false; |
| 95 | }, |
| 96 | requestPostPaintCallback: function () {}, |
| 97 | maySuspendCommit(type, props) { |
| 98 | return false; |
| 99 | }, |
| 100 | maySuspendCommitOnUpdate(type, oldProps, newProps) { |
| 101 | return false; |
| 102 | }, |
| 103 | maySuspendCommitInSyncRender(type, props) { |
| 104 | return false; |
| 105 | }, |
| 106 | preloadInstance(instance, type, props) { |
| 107 | return true; |
| 108 | }, |
| 109 | startSuspendingCommit() { |
| 110 | return null; |
| 111 | }, |
| 112 | suspendInstance(state, instance, type, props) {}, |
| 113 | suspendOnActiveViewTransition(state, container) {}, |
| 114 | waitForCommitToBeReady(state, timeoutOffset) { |
| 115 | return null; |
| 116 | }, |
| 117 | getSuspendedCommitReason(state, rootContainer) { |
| 118 | return null; |
| 119 | }, |
| 120 | supportsMutation: true, |
| 121 | }); |
| 122 | |
| 123 | const container = Renderer.createContainer( |
| 124 | rootContext, |
| 125 | ConcurrentRoot, |
| 126 | null, |
| 127 | false, |
| 128 | null, |
| 129 | '', |
| 130 | () => {}, |
| 131 | () => {}, |
| 132 | () => {}, |
| 133 | null, |
| 134 | ); |
| 135 | act(() => { |
| 136 | Renderer.updateContainer( |
| 137 | <a> |
| 138 | <b /> |
| 139 | </a>, |
| 140 | container, |
| 141 | /* parentComponent: */ null, |
| 142 | /* callback: */ null, |
| 143 | ); |
| 144 | }); |
| 145 | }); |
| 146 | }); |