aboutsummaryrefslogtreecommitdiff
path: root/node_modules/jest-snapshot/build/mockSerializer.js
blob: bf1c78d62d4488d654f60c0eee15458caa8af74f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict';

Object.defineProperty(exports, '__esModule', {
  value: true
});
exports.test = exports.serialize = exports.default = void 0;

/**
 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
const serialize = (val, config, indentation, depth, refs, printer) => {
  // Serialize a non-default name, even if config.printFunctionName is false.
  const name = val.getMockName();
  const nameString = name === 'jest.fn()' ? '' : ' ' + name;
  let callsString = '';

  if (val.mock.calls.length !== 0) {
    const indentationNext = indentation + config.indent;
    callsString =
      ' {' +
      config.spacingOuter +
      indentationNext +
      '"calls": ' +
      printer(val.mock.calls, config, indentationNext, depth, refs) +
      (config.min ? ', ' : ',') +
      config.spacingOuter +
      indentationNext +
      '"results": ' +
      printer(val.mock.results, config, indentationNext, depth, refs) +
      (config.min ? '' : ',') +
      config.spacingOuter +
      indentation +
      '}';
  }

  return '[MockFunction' + nameString + ']' + callsString;
};

exports.serialize = serialize;

const test = val => val && !!val._isMockFunction;

exports.test = test;
const plugin = {
  serialize,
  test
};
var _default = plugin;
exports.default = _default;