AsymmetricMatcher.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = exports.test = exports.serialize = void 0;
  6. var _collections = require('../collections');
  7. var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
  8. const asymmetricMatcher =
  9. typeof Symbol === 'function' && Symbol.for
  10. ? Symbol.for('jest.asymmetricMatcher')
  11. : 0x1357a5;
  12. const SPACE = ' ';
  13. const serialize = (val, config, indentation, depth, refs, printer) => {
  14. const stringedValue = val.toString();
  15. if (
  16. stringedValue === 'ArrayContaining' ||
  17. stringedValue === 'ArrayNotContaining'
  18. ) {
  19. if (++depth > config.maxDepth) {
  20. return '[' + stringedValue + ']';
  21. }
  22. return (
  23. stringedValue +
  24. SPACE +
  25. '[' +
  26. (0, _collections.printListItems)(
  27. val.sample,
  28. config,
  29. indentation,
  30. depth,
  31. refs,
  32. printer
  33. ) +
  34. ']'
  35. );
  36. }
  37. if (
  38. stringedValue === 'ObjectContaining' ||
  39. stringedValue === 'ObjectNotContaining'
  40. ) {
  41. if (++depth > config.maxDepth) {
  42. return '[' + stringedValue + ']';
  43. }
  44. return (
  45. stringedValue +
  46. SPACE +
  47. '{' +
  48. (0, _collections.printObjectProperties)(
  49. val.sample,
  50. config,
  51. indentation,
  52. depth,
  53. refs,
  54. printer
  55. ) +
  56. '}'
  57. );
  58. }
  59. if (
  60. stringedValue === 'StringMatching' ||
  61. stringedValue === 'StringNotMatching'
  62. ) {
  63. return (
  64. stringedValue +
  65. SPACE +
  66. printer(val.sample, config, indentation, depth, refs)
  67. );
  68. }
  69. if (
  70. stringedValue === 'StringContaining' ||
  71. stringedValue === 'StringNotContaining'
  72. ) {
  73. return (
  74. stringedValue +
  75. SPACE +
  76. printer(val.sample, config, indentation, depth, refs)
  77. );
  78. }
  79. return val.toAsymmetricMatcher();
  80. };
  81. exports.serialize = serialize;
  82. const test = val => val && val.$$typeof === asymmetricMatcher;
  83. exports.test = test;
  84. const plugin = {
  85. serialize,
  86. test
  87. };
  88. var _default = plugin;
  89. exports.default = _default;