ReactTestComponent.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = exports.test = exports.serialize = void 0;
  6. var _markup = require('./lib/markup');
  7. var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
  8. const testSymbol =
  9. typeof Symbol === 'function' && Symbol.for
  10. ? Symbol.for('react.test.json')
  11. : 0xea71357;
  12. const getPropKeys = object => {
  13. const {props} = object;
  14. return props
  15. ? Object.keys(props)
  16. .filter(key => props[key] !== undefined)
  17. .sort()
  18. : [];
  19. };
  20. const serialize = (object, config, indentation, depth, refs, printer) =>
  21. ++depth > config.maxDepth
  22. ? (0, _markup.printElementAsLeaf)(object.type, config)
  23. : (0, _markup.printElement)(
  24. object.type,
  25. object.props
  26. ? (0, _markup.printProps)(
  27. getPropKeys(object),
  28. object.props,
  29. config,
  30. indentation + config.indent,
  31. depth,
  32. refs,
  33. printer
  34. )
  35. : '',
  36. object.children
  37. ? (0, _markup.printChildren)(
  38. object.children,
  39. config,
  40. indentation + config.indent,
  41. depth,
  42. refs,
  43. printer
  44. )
  45. : '',
  46. config,
  47. indentation
  48. );
  49. exports.serialize = serialize;
  50. const test = val => val && val.$$typeof === testSymbol;
  51. exports.test = test;
  52. const plugin = {
  53. serialize,
  54. test
  55. };
  56. var _default = plugin;
  57. exports.default = _default;