AsymmetricMatcher.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 = Symbol.for('jest.asymmetricMatcher');
  9. const SPACE = ' ';
  10. const serialize = (val, config, indentation, depth, refs, printer) => {
  11. const stringedValue = val.toString();
  12. if (
  13. stringedValue === 'ArrayContaining' ||
  14. stringedValue === 'ArrayNotContaining'
  15. ) {
  16. if (++depth > config.maxDepth) {
  17. return '[' + stringedValue + ']';
  18. }
  19. return (
  20. stringedValue +
  21. SPACE +
  22. '[' +
  23. (0, _collections.printListItems)(
  24. val.sample,
  25. config,
  26. indentation,
  27. depth,
  28. refs,
  29. printer
  30. ) +
  31. ']'
  32. );
  33. }
  34. if (
  35. stringedValue === 'ObjectContaining' ||
  36. stringedValue === 'ObjectNotContaining'
  37. ) {
  38. if (++depth > config.maxDepth) {
  39. return '[' + stringedValue + ']';
  40. }
  41. return (
  42. stringedValue +
  43. SPACE +
  44. '{' +
  45. (0, _collections.printObjectProperties)(
  46. val.sample,
  47. config,
  48. indentation,
  49. depth,
  50. refs,
  51. printer
  52. ) +
  53. '}'
  54. );
  55. }
  56. if (
  57. stringedValue === 'StringMatching' ||
  58. stringedValue === 'StringNotMatching'
  59. ) {
  60. return (
  61. stringedValue +
  62. SPACE +
  63. printer(val.sample, config, indentation, depth, refs)
  64. );
  65. }
  66. if (
  67. stringedValue === 'StringContaining' ||
  68. stringedValue === 'StringNotContaining'
  69. ) {
  70. return (
  71. stringedValue +
  72. SPACE +
  73. printer(val.sample, config, indentation, depth, refs)
  74. );
  75. }
  76. return val.toAsymmetricMatcher();
  77. };
  78. exports.serialize = serialize;
  79. const test = val => val && val.$$typeof === asymmetricMatcher;
  80. exports.test = test;
  81. const plugin = {
  82. serialize,
  83. test
  84. };
  85. var _default = plugin;
  86. exports.default = _default;