custom-app
Version:
ITIMS��Ʒ�鿪��ר��React���,�Dz��ý��ּ�dhcc-app���������
48 lines (45 loc) • 1.35 kB
Flow
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule _DraftTestHelper
* @flow
* @format
*/
const BLACK_LIST_PROPS = ['data-reactroot'];
const transformSnapshotProps = (node: any, blackList: Array<string> = BLACK_LIST_PROPS) => {
const stack = [node];
while (stack.length) {
const node = stack.pop();
if (node.props) {
if (node.props.className) {
node.props.className = node.props.className.replace(/-/g, '__');
}
BLACK_LIST_PROPS.forEach(prop => delete node.props[prop]);
}
if (Array.isArray(node.children)) {
stack.push(...node.children);
}
}
return node;
};
const DraftTestHelper = {
/**
* This is meant to be used in combination with ReactTestRenderer
* to ensure compatibility with running our snapshot tests internally
*
* usage example:
*
* const blockNode = ReactTestRenderer.create(
* <DraftComponentFooBar {...childProps} />,
* );
*
* expect(transformSnapshotProps(blockNode.toJSON())).toMatchSnapshot();
*/
transformSnapshotProps
};
module.exports = DraftTestHelper;