asymmetric_matcher.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. 'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.test = exports.serialize = undefined;
  2. var _collections = require('../collections'); /**
  3. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  4. *
  5. * This source code is licensed under the MIT license found in the
  6. * LICENSE file in the root directory of this source tree.
  7. *
  8. *
  9. */const asymmetricMatcher = Symbol.for('jest.asymmetricMatcher');const SPACE = ' ';const serialize = exports.serialize = (val, config,
  10. indentation,
  11. depth,
  12. refs,
  13. printer) =>
  14. {
  15. const stringedValue = val.toString();
  16. if (stringedValue === 'ArrayContaining') {
  17. if (++depth > config.maxDepth) {
  18. return '[' + stringedValue + ']';
  19. }
  20. return (
  21. stringedValue +
  22. SPACE +
  23. '[' +
  24. (0, _collections.printListItems)(val.sample, config, indentation, depth, refs, printer) +
  25. ']');
  26. }
  27. if (stringedValue === 'ObjectContaining') {
  28. if (++depth > config.maxDepth) {
  29. return '[' + stringedValue + ']';
  30. }
  31. return (
  32. stringedValue +
  33. SPACE +
  34. '{' +
  35. (0, _collections.printObjectProperties)(
  36. val.sample,
  37. config,
  38. indentation,
  39. depth,
  40. refs,
  41. printer) +
  42. '}');
  43. }
  44. if (stringedValue === 'StringMatching') {
  45. return (
  46. stringedValue +
  47. SPACE +
  48. printer(val.sample, config, indentation, depth, refs));
  49. }
  50. if (stringedValue === 'StringContaining') {
  51. return (
  52. stringedValue +
  53. SPACE +
  54. printer(val.sample, config, indentation, depth, refs));
  55. }
  56. return val.toAsymmetricMatcher();
  57. };
  58. const test = exports.test = val => val && val.$$typeof === asymmetricMatcher;exports.default =
  59. { serialize, test };