2017-06-02 22:57:28 +08:00
|
|
|
/**
|
2017-09-25 04:48:13 +08:00
|
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
2017-06-02 22:57:28 +08:00
|
|
|
*
|
2017-09-25 04:48:13 +08:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2017-06-02 22:57:28 +08:00
|
|
|
*
|
|
|
|
|
* @emails react-core
|
2018-01-03 02:42:18 +08:00
|
|
|
* @jest-environment node
|
2017-06-02 22:57:28 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
let createReactNativeComponentClass;
|
|
|
|
|
let React;
|
|
|
|
|
let ReactNative;
|
|
|
|
|
|
|
|
|
|
describe('createReactNativeComponentClass', () => {
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
jest.resetModules();
|
|
|
|
|
|
2017-11-03 03:50:03 +08:00
|
|
|
createReactNativeComponentClass = require('../createReactNativeComponentClass')
|
|
|
|
|
.default;
|
2017-06-14 07:58:35 +08:00
|
|
|
React = require('react');
|
2017-10-19 07:22:21 +08:00
|
|
|
ReactNative = require('react-native-renderer');
|
2017-06-02 22:57:28 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should register viewConfigs', () => {
|
|
|
|
|
const textViewConfig = {
|
|
|
|
|
validAttributes: {},
|
|
|
|
|
uiViewClassName: 'Text',
|
|
|
|
|
};
|
|
|
|
|
const viewViewConfig = {
|
|
|
|
|
validAttributes: {},
|
|
|
|
|
uiViewClassName: 'View',
|
|
|
|
|
};
|
|
|
|
|
|
2017-09-01 04:42:27 +08:00
|
|
|
const Text = createReactNativeComponentClass(
|
|
|
|
|
textViewConfig.uiViewClassName,
|
|
|
|
|
() => textViewConfig,
|
|
|
|
|
);
|
|
|
|
|
const View = createReactNativeComponentClass(
|
|
|
|
|
viewViewConfig.uiViewClassName,
|
|
|
|
|
() => viewViewConfig,
|
|
|
|
|
);
|
2017-06-02 22:57:28 +08:00
|
|
|
|
|
|
|
|
expect(Text).not.toBe(View);
|
|
|
|
|
|
|
|
|
|
ReactNative.render(<Text />, 1);
|
|
|
|
|
ReactNative.render(<View />, 1);
|
|
|
|
|
});
|
|
|
|
|
|
2017-08-24 06:53:55 +08:00
|
|
|
it('should not allow viewConfigs with duplicate uiViewClassNames to be registered', () => {
|
|
|
|
|
const textViewConfig = {
|
|
|
|
|
validAttributes: {},
|
|
|
|
|
uiViewClassName: 'Text',
|
|
|
|
|
};
|
|
|
|
|
const altTextViewConfig = {
|
|
|
|
|
validAttributes: {},
|
|
|
|
|
uiViewClassName: 'Text', // Same
|
|
|
|
|
};
|
2017-06-02 22:57:28 +08:00
|
|
|
|
2017-09-01 04:42:27 +08:00
|
|
|
createReactNativeComponentClass(
|
|
|
|
|
textViewConfig.uiViewClassName,
|
|
|
|
|
() => textViewConfig,
|
|
|
|
|
);
|
2017-06-02 22:57:28 +08:00
|
|
|
|
2017-08-24 06:53:55 +08:00
|
|
|
expect(() => {
|
2017-09-01 04:42:27 +08:00
|
|
|
createReactNativeComponentClass(
|
|
|
|
|
altTextViewConfig.uiViewClassName,
|
|
|
|
|
() => altTextViewConfig,
|
|
|
|
|
);
|
2017-08-24 06:53:55 +08:00
|
|
|
}).toThrow('Tried to register two views with the same name Text');
|
|
|
|
|
});
|
2017-06-02 22:57:28 +08:00
|
|
|
});
|