asymmetric_matcher.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 = (val, config, indentation, depth, refs, printer) => {
  18. const stringedValue = val.toString();
  19. if (stringedValue === 'ArrayContaining') {
  20. if (++depth > config.maxDepth) {
  21. return '[' + stringedValue + ']';
  22. }
  23. return stringedValue + SPACE + '[' + (0, _collections.printListItems)(val.sample, config, indentation, depth, refs, printer) + ']';
  24. }
  25. if (stringedValue === 'ObjectContaining') {
  26. if (++depth > config.maxDepth) {
  27. return '[' + stringedValue + ']';
  28. }
  29. return stringedValue + SPACE + '{' + (0, _collections.printObjectProperties)(val.sample, config, indentation, depth, refs, printer) + '}';
  30. }
  31. if (stringedValue === 'StringMatching') {
  32. return stringedValue + SPACE + printer(val.sample, config, indentation, depth, refs);
  33. }
  34. if (stringedValue === 'StringContaining') {
  35. return stringedValue + SPACE + printer(val.sample, config, indentation, depth, refs);
  36. }
  37. return val.toAsymmetricMatcher();
  38. };
  39. const test = exports.test = val => val && val.$$typeof === asymmetricMatcher;
  40. exports.default = { serialize, test };