mock_serializer.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. const serialize = (exports.serialize = (
  6. val,
  7. config,
  8. indentation,
  9. depth,
  10. refs,
  11. printer
  12. ) => {
  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. /**
  38. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  39. *
  40. * This source code is licensed under the MIT license found in the
  41. * LICENSE file in the root directory of this source tree.
  42. *
  43. *
  44. */
  45. const test = (exports.test = val => val && !!val._isMockFunction);
  46. exports.default = {serialize: serialize, test: test};