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

Snapshot summaries can be made even more delightful #3581

Closed
excitement-engineer opened this issue May 16, 2017 · 7 comments
Closed

Snapshot summaries can be made even more delightful #3581

excitement-engineer opened this issue May 16, 2017 · 7 comments

Comments

@excitement-engineer
Copy link
Contributor

After performing a test run jest always shows a Snapshot Summary as follows:

screen shot 2017-05-16 at 13 45 17

It would be really nice to have some more information about which test created the snapshot. The same goes for obsolete snapshots, it simply shows "1 obsolete snapshot found", I think it is really useful to have some more information such as the name of the obsolete snapshot for example to prevent users from accidentally deleting snapshots during refactoring for example.

I think that adding some more information to the summary can make the snapshot experience even more awesome!

What do you guys think?

If you feel that this feature is a worthy addition to Jest then I would be happy to work on it:)

@excitement-engineer excitement-engineer changed the title Snapshot summary can be made even more awesome Snapshot summaries can be made even more delightful May 16, 2017
@lstkz
Copy link
Contributor

lstkz commented May 25, 2017

I am using snapshots to test complex objects and arrays, not only react components.
When I run tests for the first time and I always must find them in the snap file and verify.
It would be great if the console output can provide more information.
For example: mapping between the line number and the test name.

btw
There is also another problem. All snapshots are always sorted alphabetically in the snap file. Is it possible to match the same order from the test.js file?

@excitement-engineer
Copy link
Contributor Author

I agree that this could be improved, for large snapshot files I also find myself searching for the specific snapshot. If you have some ideas that you would like to contribute here then I encourage you to create a PR!

I created a PR #3660 to try and solve the issue I highlighted, would be great to hear your feedback

@lstkz
Copy link
Contributor

lstkz commented May 28, 2017

Is it possible to add an option to disable creating new snapshots?

I started developing in this way:

  1. Create a dummy snapshot.
describe('sample', () => {
  it('foo', () => {
    expect('').toMatchSnapshot();
  });
});
  1. It will create a new snapshot with empty string.
  2. Implement code
  3. Update the test
describe('sample', () => {
  it('foo', () => {
    const component = shallow(
      <Foo />
    );
    expect(something).toMatchSnapshot();
  });
});
  1. Check if the test diff looks good.
  2. Press u.

When using this approach I don't need to find the code in snapshot files, but I think 1. step could be omitted.
There is already --ci flag that doesn't create new snapshots, but it doesn't output the result.

@lstkz
Copy link
Contributor

lstkz commented May 30, 2017

See #3693

@josh-stevens
Copy link

+1 for configuring the order that snapshot files are generated. When I test react saga's, it would be very nice to be able to read the snapshot in the order the steps occur rather than alphabetical. The way it works now, it groups all of my dispatch tests together, all of my selector tests together, etc. because of alphabetical sorting "it should dispatch", "it should select"...

It would be nice to have it sort in the same order as the test file, so I could put the snapshot file side by side with the test file and make sure everything is coming out properly.

@cpojer
Copy link
Member

cpojer commented Aug 24, 2017

Will be in Jest 21

@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 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants