asymmetric_matcher.js 2.0 KB

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