mockSerializer.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.test = exports.serialize = exports.default = void 0;
  6. /**
  7. * Copyright (c) Meta Platforms, Inc. and affiliates.
  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 = ` {${config.spacingOuter}${indentationNext}"calls": ${printer(
  20. val.mock.calls,
  21. config,
  22. indentationNext,
  23. depth,
  24. refs
  25. )}${config.min ? ', ' : ','}${
  26. config.spacingOuter
  27. }${indentationNext}"results": ${printer(
  28. val.mock.results,
  29. config,
  30. indentationNext,
  31. depth,
  32. refs
  33. )}${config.min ? '' : ','}${config.spacingOuter}${indentation}}`;
  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;