/
githubmr
/
facebook-react
Обзор
Документация
Войти
/
githubmr
/
facebook-react
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
packages/react-dom/src/__tests__/ReactMockedComponent-test.js
57 строк
2 KB
Jack Pope
Use createRoot in ReactMockedComponent-test (#28087)
27 янв 2024, 01:28
Не верифицирован
27 янв 2024, 01:28
54f2314
Код
Авторство
О чём код?
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @emails react-core */ 'use strict'; let React; let ReactDOMClient; let act; let MockedComponent; let ReactDOMServer; describe('ReactMockedComponent', () => { beforeEach(() => { React = require('react'); ReactDOMClient = require('react-dom/client'); ReactDOMServer = require('react-dom/server'); act = require('internal-test-utils').act; MockedComponent = class extends React.Component { render() { throw new Error('Should not get here.'); } }; // This is close enough to what a Jest mock would give us. MockedComponent.prototype.render = jest.fn(); }); it('should allow a mocked component to be rendered', async () => { const container = document.createElement('container'); const root = ReactDOMClient.createRoot(container); await act(() => { root.render(<MockedComponent />); }); }); it('should allow a mocked component to be updated in dev', async () => { const container = document.createElement('container'); const root = ReactDOMClient.createRoot(container); await act(() => { root.render(<MockedComponent />); }); await act(() => { root.render(<MockedComponent />); }); }); it('should allow a mocked component to be rendered in dev (SSR)', () => { ReactDOMServer.renderToString(<MockedComponent />); }); });