Skip to content
/ jest Public
forked from jestjs/jest

Commit

Permalink
Print jest mock fuctions as MockFunction in jest-snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Nov 3, 2017
1 parent 0e35f7c commit 717a551
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`empty with no calls mock 1`] = `
Object {
MockFunction {
"calls": Array [],
"name": "jest.fn()",
}
`;

exports[`instantiated mock 1`] = `
Object {
MockFunction {
"calls": Array [
Array [
Object {
Expand All @@ -21,7 +21,7 @@ Object {
`;

exports[`mock with calls 1`] = `
Object {
MockFunction {
"calls": Array [
Array [],
Array [
Expand All @@ -36,7 +36,7 @@ Object {
`;

exports[`mock with name 1`] = `
Object {
MockFunction {
"calls": Array [],
"name": "name of mock is nice",
}
Expand Down
17 changes: 12 additions & 5 deletions packages/jest-snapshot/src/mock_serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@ export const serialize = (
refs: Refs,
printer: Printer,
): string => {
const mockObject = {
calls: val.mock.calls,
name: val.getMockName(),
};
const indentationNext = indentation + config.indent;

return printer(mockObject, config, indentation, depth, refs);
return (
'MockFunction {\n' +
indentationNext +
'"calls": ' +
printer(val.mock.calls, config, indentationNext, depth, refs) +
',\n' +
indentationNext +
'"name": ' +
printer(val.getMockName(), config, indentationNext, depth, refs) +
',\n}'
);
};

export const test = (val: any) => val && !!val._isMockFunction;
Expand Down

0 comments on commit 717a551

Please sign in to comment.