UNPKG

1.43 kBJavaScriptView Raw
1"use strict";
2
3/**
4 * Copyright (c) Facebook, Inc. and its affiliates.
5 *
6 * This source code is licensed under the MIT license found in the
7 * LICENSE file in the root directory of this source tree.
8 *
9 *
10 * @format
11 * @emails oncall+draft_js
12 */
13var BLACK_LIST_PROPS = ['data-reactroot'];
14
15var transformSnapshotProps = function transformSnapshotProps(node) {
16 var blackList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : BLACK_LIST_PROPS;
17 var stack = [node];
18
19 var _loop = function _loop() {
20 var node = stack.pop();
21
22 if (node.props) {
23 if (node.props.className) {
24 node.props.className = node.props.className.replace(/-/g, '__');
25 }
26
27 BLACK_LIST_PROPS.forEach(function (prop) {
28 return delete node.props[prop];
29 });
30 }
31
32 if (Array.isArray(node.children)) {
33 stack.push.apply(stack, node.children);
34 }
35 };
36
37 while (stack.length) {
38 _loop();
39 }
40
41 return node;
42};
43
44var DraftTestHelper = {
45 /**
46 * This is meant to be used in combination with ReactTestRenderer
47 * to ensure compatibility with running our snapshot tests internally
48 *
49 * usage example:
50 *
51 * const blockNode = ReactTestRenderer.create(
52 * <DraftComponentFooBar {...childProps} />,
53 * );
54 *
55 * expect(transformSnapshotProps(blockNode.toJSON())).toMatchSnapshot();
56 */
57 transformSnapshotProps: transformSnapshotProps
58};
59module.exports = DraftTestHelper;
\No newline at end of file