Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
include custom mock name in toBeCalled matcher
  • Loading branch information
leggsimon committed May 16, 2018
commit cd3515e0902e4109d0418b319c97598778f466a7
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ Got:
exports[`toBeCalled includes the custom mock name in the error message 1`] = `
"<dim>expect(</><red>named-mock</><dim>).not.toBeCalled(</><dim>)</>

Expected mock function not to be called but it was called with:
Expected mock function \\"named-mock\\" not to be called but it was called with:
<red>[]</>"
`;

Expand Down Expand Up @@ -791,7 +791,7 @@ Got:
exports[`toHaveBeenCalled includes the custom mock name in the error message 1`] = `
"<dim>expect(</><red>named-mock</><dim>).not.toHaveBeenCalled(</><dim>)</>

Expected mock function not to be called but it was called with:
Expected mock function \\"named-mock\\" not to be called but it was called with:
<red>[]</>"
`;

Expand Down
5 changes: 3 additions & 2 deletions packages/expect/src/spy_matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const createToBeCalledMatcher = matcherName => (received, expected) => {
const receivedIsSpy = isSpy(received);
const type = receivedIsSpy ? 'spy' : 'mock function';
const receivedName = receivedIsSpy ? 'spy' : received.getMockName();
const identifier = receivedIsSpy || receivedName === 'jest.fn()' ? type : `${type} "${receivedName}"`;
const count = receivedIsSpy
? received.calls.count()
: received.mock.calls.length;
Expand All @@ -45,12 +46,12 @@ const createToBeCalledMatcher = matcherName => (received, expected) => {
? () =>
matcherHint('.not' + matcherName, receivedName, '') +
'\n\n' +
`Expected ${type} not to be called ` +
`Expected ${identifier} not to be called ` +
formatReceivedCalls(calls, CALL_PRINT_LIMIT, {sameSentence: true})
: () =>
matcherHint(matcherName, receivedName, '') +
'\n\n' +
`Expected ${type} to have been called, but it was not called.`;
`Expected ${identifier} to have been called, but it was not called.`;

return {message, pass};
};
Expand Down