Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

59 linhas
1.4 KiB

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