Adding test for components rendered with Fabric with Paper's setNativeProps

This commit is contained in:
Eli White 2019-02-20 15:55:00 -08:00
parent ef52e22e89
commit a5e5f2a350
2 changed files with 24 additions and 2 deletions

View File

@ -19,7 +19,7 @@ import UIManager from 'UIManager';
const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
export function setNativeProps(handle, nativeProps: Object) {
export function setNativeProps(handle: any, nativeProps: Object) {
if (handle._nativeTag == null) {
warningWithoutStack(
handle._nativeTag != null,
@ -34,7 +34,6 @@ export function setNativeProps(handle, nativeProps: Object) {
}
const updatePayload = create(nativeProps, handle.viewConfig.validAttributes);
// Avoid the overhead of bridge calls if there's no update.
// This is an expensive no-op for Android, and causes an unnecessary
// view invalidation for certain components (eg RCTTextInput) on iOS.

View File

@ -13,12 +13,14 @@
let React;
let ReactFabric;
let ReactNative;
let UIManager;
let createReactNativeComponentClass;
describe('ReactFabric', () => {
beforeEach(() => {
jest.resetModules();
ReactNative = require('react-native-renderer');
UIManager = require('UIManager');
jest.resetModules();
jest.mock('shared/ReactFeatureFlags', () =>
require('shared/forks/ReactFeatureFlags.native-oss'),
@ -49,4 +51,25 @@ describe('ReactFabric', () => {
let handle = ReactNative.findNodeHandle(ref.current);
expect(handle).toBe(2);
});
it('sets native props with setNativeProps on Fabric nodes with the RN renderer', () => {
UIManager.updateView.mockReset();
const View = createReactNativeComponentClass('RCTView', () => ({
validAttributes: {title: true},
uiViewClassName: 'RCTView',
}));
let ref = React.createRef();
ReactFabric.render(<View title="bar" ref={ref} />, 11);
expect(UIManager.updateView).not.toBeCalled();
ReactNative.setNativeProps(ref.current, {title: 'baz'});
expect(UIManager.updateView).toHaveBeenCalledTimes(1);
expect(UIManager.updateView).toHaveBeenCalledWith(
expect.any(Number),
'RCTView',
{title: 'baz'},
);
});
});