mock_serializer.js 1.1 KB

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. const serialize = exports.serialize = (val, config, indentation, depth, refs, printer) => {
  6. // Serialize a non-default name, even if config.printFunctionName is false.
  7. const name = val.getMockName();
  8. const nameString = name === 'jest.fn()' ? '' : ' ' + name;
  9. let callsString = '';
  10. if (val.mock.calls.length !== 0) {
  11. const indentationNext = indentation + config.indent;
  12. callsString = ' {' + config.spacingOuter + indentationNext + '"calls": ' + printer(val.mock.calls, config, indentationNext, depth, refs) + (config.min ? '' : ',') + config.spacingOuter + indentation + '}';
  13. }
  14. return '[MockFunction' + nameString + ']' + callsString;
  15. }; /**
  16. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  17. *
  18. * This source code is licensed under the MIT license found in the
  19. * LICENSE file in the root directory of this source tree.
  20. *
  21. *
  22. */
  23. const test = exports.test = val => val && !!val._isMockFunction;
  24. exports.default = { serialize, test };