mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
RN: Fix mockComponent for Functional Components (#45196)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45196 Currently, `mockComponent` makes a false assumption that if a component is a function, it extends `React.Component`. There's a bunch of problems with this mocking setup with requiring mock components that extend `React.Component`, but this change does not attemp to solve that. This change unblocks future refactors to make native components export functional components (that are neither class component nor `forwardRef` results). Changelog: [General][Changed] - Fixed native component mocking in Jest unit tests to support functional components Reviewed By: javache Differential Revision: D59097730 fbshipit-source-id: ca2784ac3baa9ab4ab6a503c5fd6437c60179352
This commit is contained in:
committed by
Facebook GitHub Bot
parent
3965b7d78b
commit
fb58494283
+4
-1
@@ -16,7 +16,10 @@ module.exports = (moduleName, instanceMethods, isESModule) => {
|
||||
const React = require('react');
|
||||
|
||||
const SuperClass =
|
||||
typeof RealComponent === 'function' ? RealComponent : React.Component;
|
||||
typeof RealComponent === 'function' &&
|
||||
RealComponent.prototype.constructor instanceof React.Component
|
||||
? RealComponent
|
||||
: React.Component;
|
||||
|
||||
const name =
|
||||
RealComponent.displayName ||
|
||||
|
||||
Reference in New Issue
Block a user