ReactTestComponent.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 = Symbol.for('react.test.json');
  9. const getPropKeys = object => {
  10. const props = object.props;
  11. return props
  12. ? Object.keys(props)
  13. .filter(key => props[key] !== undefined)
  14. .sort()
  15. : [];
  16. };
  17. const serialize = (object, config, indentation, depth, refs, printer) =>
  18. ++depth > config.maxDepth
  19. ? (0, _markup.printElementAsLeaf)(object.type, config)
  20. : (0, _markup.printElement)(
  21. object.type,
  22. object.props
  23. ? (0, _markup.printProps)(
  24. getPropKeys(object),
  25. object.props,
  26. config,
  27. indentation + config.indent,
  28. depth,
  29. refs,
  30. printer
  31. )
  32. : '',
  33. object.children
  34. ? (0, _markup.printChildren)(
  35. object.children,
  36. config,
  37. indentation + config.indent,
  38. depth,
  39. refs,
  40. printer
  41. )
  42. : '',
  43. config,
  44. indentation
  45. );
  46. exports.serialize = serialize;
  47. const test = val => val && val.$$typeof === testSymbol;
  48. exports.test = test;
  49. const plugin = {
  50. serialize,
  51. test
  52. };
  53. var _default = plugin;
  54. exports.default = _default;