1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  3.  *
    
  4.  * This source code is licensed under the MIT license found in the
    
  5.  * LICENSE file in the root directory of this source tree.
    
  6.  *
    
  7.  * @emails react-core
    
  8.  * @jest-environment node
    
  9.  */
    
  10. 
    
  11. 'use strict';
    
  12. 
    
  13. let createReactNativeComponentClass;
    
  14. let React;
    
  15. let ReactNative;
    
  16. 
    
  17. describe('createReactNativeComponentClass', () => {
    
  18.   beforeEach(() => {
    
  19.     jest.resetModules();
    
  20. 
    
  21.     createReactNativeComponentClass =
    
  22.       require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
    
  23.         .ReactNativeViewConfigRegistry.register;
    
  24.     React = require('react');
    
  25.     ReactNative = require('react-native-renderer');
    
  26.   });
    
  27. 
    
  28.   it('should register viewConfigs', () => {
    
  29.     const textViewConfig = {
    
  30.       validAttributes: {},
    
  31.       uiViewClassName: 'Text',
    
  32.     };
    
  33.     const viewViewConfig = {
    
  34.       validAttributes: {},
    
  35.       uiViewClassName: 'View',
    
  36.     };
    
  37. 
    
  38.     const Text = createReactNativeComponentClass(
    
  39.       textViewConfig.uiViewClassName,
    
  40.       () => textViewConfig,
    
  41.     );
    
  42.     const View = createReactNativeComponentClass(
    
  43.       viewViewConfig.uiViewClassName,
    
  44.       () => viewViewConfig,
    
  45.     );
    
  46. 
    
  47.     expect(Text).not.toBe(View);
    
  48. 
    
  49.     ReactNative.render(<Text />, 1);
    
  50.     ReactNative.render(<View />, 1);
    
  51.   });
    
  52. 
    
  53.   it('should not allow viewConfigs with duplicate uiViewClassNames to be registered', () => {
    
  54.     const textViewConfig = {
    
  55.       validAttributes: {},
    
  56.       uiViewClassName: 'Text',
    
  57.     };
    
  58.     const altTextViewConfig = {
    
  59.       validAttributes: {},
    
  60.       uiViewClassName: 'Text', // Same
    
  61.     };
    
  62. 
    
  63.     createReactNativeComponentClass(
    
  64.       textViewConfig.uiViewClassName,
    
  65.       () => textViewConfig,
    
  66.     );
    
  67. 
    
  68.     expect(() => {
    
  69.       createReactNativeComponentClass(
    
  70.         altTextViewConfig.uiViewClassName,
    
  71.         () => altTextViewConfig,
    
  72.       );
    
  73.     }).toThrow('Tried to register two views with the same name Text');
    
  74.   });
    
  75. });