MCPcopy
hub / github.com/facebook/react / render

Function render

packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js:131–174  ·  view source on GitHub ↗
(source)

Source from the content-addressed store, hash-verified

129 ['TypeScript syntax', executeTypescript, testTypeScript],
130 ])('%s', (language, execute, runTest) => {
131 async function render(source) {
132 const Component = execute(source);
133 await act(() => {
134 root.render(<Component />);
135 });
136 // Module initialization shouldn't be counted as a hot update.
137 expect(ReactFreshRuntime.performReactRefresh()).toBe(null);
138 }
139
140 async function patch(source) {
141 const prevExports = exportsObj;
142 execute(source);
143 const nextExports = exportsObj;
144
145 // Check if exported families have changed.
146 // (In a real module system we'd do this for *all* exports.)
147 // For example, this can happen if you convert a class to a function.
148 // Or if you wrap something in a HOC.
149 const didExportsChange =
150 ReactFreshRuntime.getFamilyByType(prevExports.default) !==
151 ReactFreshRuntime.getFamilyByType(nextExports.default);
152 if (didExportsChange) {
153 // In a real module system, we would propagate such updates upwards,
154 // and re-execute modules that imported this one. (Just like if we edited them.)
155 // This makes adding/removing/renaming exports re-render references to them.
156 // Here, we'll just force a re-render using the newer type to emulate this.
157 const NextComponent = nextExports.default;
158 await act(() => {
159 root.render(<NextComponent />);
160 });
161 }
162 await act(() => {
163 const result = ReactFreshRuntime.performReactRefresh();
164 if (!didExportsChange) {
165 // Normally we expect that some components got updated in our tests.
166 expect(result).not.toBe(null);
167 } else {
168 // However, we have tests where we convert functions to classes,
169 // and in those cases it's expected nothing would get updated.
170 // (Instead, the export change branch above would take care of it.)
171 }
172 });
173 expect(ReactFreshRuntime._getMountedRootCount()).toBe(1);
174 }
175
176 runTest(render, patch);
177 });

Callers 2

testJavaScriptFunction · 0.70
testTypeScriptFunction · 0.70

Calls 4

executeFunction · 0.85
renderMethod · 0.65
toBeMethod · 0.65
actFunction · 0.50

Tested by

no test coverage detected