Skip to content

Commit

Permalink
Adding setNativeProps tests for NativeMethodsMixin (#14901)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSavior committed Feb 20, 2019
1 parent b96b61d commit 4f4aa69
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/react-native-renderer/src/NativeMethodsMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ export default function(
return;
}

const nativeTag =
maybeInstance._nativeTag || maybeInstance.canonical._nativeTag;
const viewConfig: ReactNativeBaseComponentViewConfig<> =
maybeInstance.viewConfig;
maybeInstance.viewConfig || maybeInstance.canonical.viewConfig;

if (__DEV__) {
warnForStyleProps(nativeProps, viewConfig.validAttributes);
Expand All @@ -156,7 +158,7 @@ export default function(
// view invalidation for certain components (eg RCTTextInput) on iOS.
if (updatePayload != null) {
UIManager.updateView(
maybeInstance._nativeTag,
nativeTag,
viewConfig.uiViewClassName,
updatePayload,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@

let React;
let ReactFabric;
let createReactClass;
let createReactNativeComponentClass;
let UIManager;
let FabricUIManager;
let StrictMode;
let NativeMethodsMixin;

jest.mock('shared/ReactFeatureFlags', () =>
require('shared/forks/ReactFeatureFlags.native-oss'),
Expand All @@ -30,8 +32,16 @@ describe('ReactFabric', () => {
ReactFabric = require('react-native-renderer/fabric');
FabricUIManager = require('FabricUIManager');
UIManager = require('UIManager');
createReactClass = require('create-react-class/factory')(
React.Component,
React.isValidElement,
new React.Component().updater,
);
createReactNativeComponentClass = require('ReactNativeViewConfigRegistry')
.register;
NativeMethodsMixin =
ReactFabric.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
.NativeMethodsMixin;
});

it('should be able to create and render a native component', () => {
Expand Down Expand Up @@ -169,7 +179,14 @@ describe('ReactFabric', () => {
}
}

[View, Subclass].forEach(Component => {
const CreateClass = createReactClass({
mixins: [NativeMethodsMixin],
render: () => {
return <View />;
},
});

[View, Subclass, CreateClass].forEach(Component => {
UIManager.updateView.mockReset();

let viewRef;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
let React;
let StrictMode;
let ReactNative;
let createReactClass;
let createReactNativeComponentClass;
let UIManager;
let NativeMethodsMixin;

describe('ReactNative', () => {
beforeEach(() => {
Expand All @@ -24,8 +26,16 @@ describe('ReactNative', () => {
StrictMode = React.StrictMode;
ReactNative = require('react-native-renderer');
UIManager = require('UIManager');
createReactClass = require('create-react-class/factory')(
React.Component,
React.isValidElement,
new React.Component().updater,
);
createReactNativeComponentClass = require('ReactNativeViewConfigRegistry')
.register;
NativeMethodsMixin =
ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
.NativeMethodsMixin;
});

it('should be able to create and render a native component', () => {
Expand Down Expand Up @@ -100,7 +110,14 @@ describe('ReactNative', () => {
}
}

[View, Subclass].forEach(Component => {
const CreateClass = createReactClass({
mixins: [NativeMethodsMixin],
render: () => {
return <View />;
},
});

[View, Subclass, CreateClass].forEach(Component => {
UIManager.updateView.mockReset();

let viewRef;
Expand Down

0 comments on commit 4f4aa69

Please sign in to comment.