react_test_component.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.test = exports.serialize = undefined;
  6. var _markup = require('./lib/markup');
  7. /**
  8. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  9. *
  10. * This source code is licensed under the MIT license found in the
  11. * LICENSE file in the root directory of this source tree.
  12. *
  13. *
  14. */
  15. const testSymbol = Symbol.for('react.test.json');
  16. const getPropKeys = object => {
  17. const props = object.props;
  18. return props
  19. ? Object.keys(props)
  20. .filter(key => props[key] !== undefined)
  21. .sort()
  22. : [];
  23. };
  24. const serialize = (exports.serialize = (
  25. object,
  26. config,
  27. indentation,
  28. depth,
  29. refs,
  30. printer
  31. ) =>
  32. ++depth > config.maxDepth
  33. ? (0, _markup.printElementAsLeaf)(object.type, config)
  34. : (0, _markup.printElement)(
  35. object.type,
  36. object.props
  37. ? (0, _markup.printProps)(
  38. getPropKeys(object),
  39. // Despite ternary expression, Flow 0.51.0 found incorrect error:
  40. // undefined is incompatible with the expected param type of Object
  41. // $FlowFixMe
  42. object.props,
  43. config,
  44. indentation + config.indent,
  45. depth,
  46. refs,
  47. printer
  48. )
  49. : '',
  50. object.children
  51. ? (0, _markup.printChildren)(
  52. object.children,
  53. config,
  54. indentation + config.indent,
  55. depth,
  56. refs,
  57. printer
  58. )
  59. : '',
  60. config,
  61. indentation
  62. ));
  63. const test = (exports.test = val => val && val.$$typeof === testSymbol);
  64. exports.default = {serialize: serialize, test: test};