Files
react-native/Libraries/Utilities/__tests__/verifyComponentAttributeEquivalence-test.js
T
Tim Yung 69b4611049 RN: Hoist Reflection from Verification
Summary:
Hoists the call to `getNativeComponentAttributes` out of the verification function so that it's easier to keep track of when this function is and is not called.

The purpose of this will become clearer in a future refactor.

Changelog:
[Internal]

Reviewed By: ejanzer

Differential Revision: D25072600

fbshipit-source-id: bc42461baae3476fa7ecb6186c4256dd23921ed5
2020-11-18 21:19:12 -08:00

104 lines
2.8 KiB
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @emails oncall+react_native
*/
'use strict';
jest.dontMock('../verifyComponentAttributeEquivalence');
const verifyComponentAttributeEquivalence = require('../verifyComponentAttributeEquivalence')
.default;
const TestComponentNativeViewConfig = {
uiViewClassName: 'TestComponent',
NativeProps: {
value: 'BOOL',
},
bubblingEventTypes: {
topChange: {
phasedRegistrationNames: {
bubbled: 'onChange',
captured: 'onChangeCapture',
},
},
},
directEventTypes: {
topAccessibilityAction: {
registrationName: 'onAccessibilityAction',
},
},
validAttributes: {
borderColor: true,
style: {
borderColor: true,
transform: 'CATransform3D',
},
transform: 'CATransform3D',
},
};
describe('verifyComponentAttributeEquivalence', () => {
beforeEach(() => {
global.__DEV__ = true;
console.error = jest.fn();
jest.resetModules();
});
it('should not verify in prod', () => {
global.__DEV__ = false;
verifyComponentAttributeEquivalence(TestComponentNativeViewConfig, {});
});
it('should not error with native config that is a subset of the given config', () => {
const configWithAdditionalProperties = {
...TestComponentNativeViewConfig,
bubblingEventTypes: {
...TestComponentNativeViewConfig.bubblingEventTypes,
topFocus: {
phasedRegistrationNames: {
bubbled: 'onFocus',
captured: 'onFocusCapture',
},
},
},
directEventTypes: {
...TestComponentNativeViewConfig.directEventTypes,
topSlidingComplete: {
registrationName: 'onSlidingComplete',
},
},
validAttributes: {
...TestComponentNativeViewConfig.validAttributes,
active: true,
},
};
verifyComponentAttributeEquivalence(
TestComponentNativeViewConfig,
configWithAdditionalProperties,
);
expect(console.error).not.toBeCalled();
});
it('should error if given config is missing native config properties', () => {
verifyComponentAttributeEquivalence(TestComponentNativeViewConfig, {});
expect(console.error).toBeCalledTimes(3);
expect(console.error).toBeCalledWith(
"'TestComponent' has a view config that does not match native. 'validAttributes' is missing: borderColor, style",
);
expect(console.error).toBeCalledWith(
"'TestComponent' has a view config that does not match native. 'bubblingEventTypes' is missing: topChange",
);
expect(console.error).toBeCalledWith(
"'TestComponent' has a view config that does not match native. 'directEventTypes' is missing: topAccessibilityAction",
);
});
});