Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature a mock’s name more prominently in a test failure. #6192

Closed
leggsimon opened this issue May 15, 2018 · 2 comments · Fixed by #6199
Closed

Feature a mock’s name more prominently in a test failure. #6192

leggsimon opened this issue May 15, 2018 · 2 comments · Fixed by #6199

Comments

@leggsimon
Copy link
Contributor

🚀 Feature Proposal

Feature a mock’s name more prominently in a test failure.

Motivation

I love that you've added the ability to be able to name mocks but, in order to make the output error messages easier to read and understand I propose including a mock’s name in the error message.
Rather than Expected mock function to have been called.
Something like Expected the mock function 'myMockedFunction' to have been called..

Now I recognise that currently you include expect(myMockedFunction).toBeCalled() on the line above but I must admit, personally, because it's in grey I assume it isn't the most important information in the error message.

Am happy do submit a PR if you want.

Example

Given this short example

test('should show the name of the mock in the test', () => {
    const fn = jest.fn().mockName('myMockedFunction');

    expect(fn).toBeCalled();
});

this currently fails with:

  ● should show the name of the mock in the test

    expect(myMockedFunction).toBeCalled()

    Expected mock function to have been called.

      2 |     const fn = jest.fn().mockName('myMockedFunction');
      3 |
    > 4 |     expect(fn).toBeCalled();
      5 | });

I propose it failing with

  ● should show the name of the mock in the test

    expect(myMockedFunction).toBeCalled()

    Expected mock function 'myMockedFunction' to have been called.

      2 |     const fn = jest.fn().mockName('myMockedFunction');
      3 |
    > 4 |     expect(fn).toBeCalled();
      5 | });

Pitch

Because the improvement exists in the expect module which is part of the core package.

@SimenB
Copy link
Member

SimenB commented May 15, 2018

Yeah, I think that makes sense. Wanna send a PR for it?

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants