mockSerializer.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = exports.test = exports.serialize = void 0;
  6. /**
  7. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  8. *
  9. * This source code is licensed under the MIT license found in the
  10. * LICENSE file in the root directory of this source tree.
  11. */
  12. const serialize = (val, config, indentation, depth, refs, printer) => {
  13. // Serialize a non-default name, even if config.printFunctionName is false.
  14. const name = val.getMockName();
  15. const nameString = name === 'jest.fn()' ? '' : ' ' + name;
  16. let callsString = '';
  17. if (val.mock.calls.length !== 0) {
  18. const indentationNext = indentation + config.indent;
  19. callsString =
  20. ' {' +
  21. config.spacingOuter +
  22. indentationNext +
  23. '"calls": ' +
  24. printer(val.mock.calls, config, indentationNext, depth, refs) +
  25. (config.min ? ', ' : ',') +
  26. config.spacingOuter +
  27. indentationNext +
  28. '"results": ' +
  29. printer(val.mock.results, config, indentationNext, depth, refs) +
  30. (config.min ? '' : ',') +
  31. config.spacingOuter +
  32. indentation +
  33. '}';
  34. }
  35. return '[MockFunction' + nameString + ']' + callsString;
  36. };
  37. exports.serialize = serialize;
  38. const test = val => val && !!val._isMockFunction;
  39. exports.test = test;
  40. const plugin = {
  41. serialize,
  42. test
  43. };
  44. var _default = plugin;
  45. exports.default = _default;