AsymmetricMatcher.js 2.3 KB

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