Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding setNativeProps tests for NativeMethodsMixin #14901

Merged
merged 1 commit into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied this from

createReactClass = require('create-react-class/factory')(
React.Component,
React.isValidElement,
new React.Component().updater,

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