main
js 57 lines 1.51 KB
Raw
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 */
9
10 'use strict';
11
12 let React;
13 let ReactDOMClient;
14 let act;
15
16 let MockedComponent;
17 let ReactDOMServer;
18
19 describe('ReactMockedComponent', () => {
20 beforeEach(() => {
21 React = require('react');
22 ReactDOMClient = require('react-dom/client');
23 ReactDOMServer = require('react-dom/server');
24 act = require('internal-test-utils').act;
25
26 MockedComponent = class extends React.Component {
27 render() {
28 throw new Error('Should not get here.');
29 }
30 };
31 // This is close enough to what a Jest mock would give us.
32 MockedComponent.prototype.render = jest.fn();
33 });
34
35 it('should allow a mocked component to be rendered', async () => {
36 const container = document.createElement('container');
37 const root = ReactDOMClient.createRoot(container);
38 await act(() => {
39 root.render(<MockedComponent />);
40 });
41 });
42
43 it('should allow a mocked component to be updated in dev', async () => {
44 const container = document.createElement('container');
45 const root = ReactDOMClient.createRoot(container);
46 await act(() => {
47 root.render(<MockedComponent />);
48 });
49 await act(() => {
50 root.render(<MockedComponent />);
51 });
52 });
53
54 it('should allow a mocked component to be rendered in dev (SSR)', () => {
55 ReactDOMServer.renderToString(<MockedComponent />);
56 });
57 });