/
githubmr
/
facebook-react-native
Обзор
Документация
Войти
/
githubmr
/
facebook-react-native
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
v0.81.3
packages/react-native/jest/mockNativeComponent.js
51 строка
1 KB
Tim Yung
RN: Refactor Jest Default Mocks (#51669)
29 май 2025, 17:52
29 май 2025, 17:52
1fd9508
Код
Авторство
О чём код?
/** * 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. * * @flow strict * @format */ import type {HostInstance} from '../src/private/types/HostInstance'; import * as React from 'react'; import {createElement} from 'react'; let nativeTag = 1; type MockNativeComponent<TProps: {...}> = component( ref?: ?React.RefSetter<HostInstance>, ...props: TProps ); export default function mockNativeComponent<TProps: {...}>( viewName: string, ): MockNativeComponent<TProps> { const Component = class extends React.Component<TProps> { _nativeTag: number = nativeTag++; render(): React.Node { // $FlowIgnore[not-a-function] // $FlowIgnore[prop-missing] return createElement(viewName, this.props, this.props.children); } // The methods that exist on host components blur: () => void = jest.fn(); focus: () => void = jest.fn(); measure: () => void = jest.fn(); measureInWindow: () => void = jest.fn(); measureLayout: () => void = jest.fn(); setNativeProps: () => void = jest.fn(); }; if (viewName === 'RCTView') { Component.displayName = 'View'; } else { Component.displayName = viewName; } return Component; }