Jest: Diff colors should show green for insert, red for delete

Created on 31 Jan 2018  路  7Comments  路  Source: facebook/jest

FEATURE REQUEST

When snapshot testing, the console shows differences between old and new snapshots with a DIFF view. The colors in the DIFF view are reversed as opposed to most other popular tools. Normally green is for inserts and red is for deletions. Jest shows this the wrong way around which is very confusing when using jest in combination with other diff tools (like bitbucket, git diff, intelliJ, etc).

So this feature request is: make deleted rows show as RED and inserted rows show as GREEN.

Feature Request Discussion

Most helpful comment

I and two others on my team spent more time that we care to admit publicly tripped up over this.

Because of the removal of undefined props in Jest 23, we started seeing these failures and kept thinking to ourselves, "Why is it adding undefined props when it should be removing them?!".

It drove us mad until I realized the colors were flipped when I noticed the - and + next to Snapshot and Received.

Screen Shot 2019-06-15 at 3 45 59 PM

I mean, we're fine now, as this will forever be seared into our brains going forward, but it was _completely opposite_ compared to what we're all accustom to seeing in the dev world, like here on GitHub.

All 7 comments

See https://github.com/facebook/jest/pull/2347#issuecomment-267639148 for some discussion.

I'm still in favour of doing something like this 馃檪

This is intended behavior.

Basically, in snapshot land GREEN is the accepted previous state. If something changed, Jest highlights new changes in RED to draw your attention, as this is potentially something that's failing, or just something that needs to be updated.

We get that it may be unintuitive at first glance, but it really makes sense. IMO we shouldn't change it.

It might be true that green was the accepted state... but this is a diff between the old snapshot and the new snapshot (the new snapshot will in most cases be accepted anyway). I still feel that stuff that is/will be inserted after a change should be + green and stuff that is/will be removed should be - red..

The number of times me and my coworkers have been searching for a problem that wasn't there because we simply misinterpreted the diff does not weigh up to being 'correct in snapshot land'. At least for us it doesn't.

Maybe add a config option to allow users to configure their own colors? That way everybody's happy..

the new snapshot will in most cases be accepted anyway

Let's not generalize about "most cases", as it varies for different projects. But I'd be supportive to adding a config option, if it's not going to introduce a lot of extra complexity.

That would be awesome!

I agree that it might not be the case for every project indeed.

Thanks for being supportive.

I鈥檇 like to propose some coloring changes. Since the rest of the snap is grey, what if the original diff was just white with the change being yellow/amber?

That way the diff is more of a warning than an error, since you might actually intend the change.

I and two others on my team spent more time that we care to admit publicly tripped up over this.

Because of the removal of undefined props in Jest 23, we started seeing these failures and kept thinking to ourselves, "Why is it adding undefined props when it should be removing them?!".

It drove us mad until I realized the colors were flipped when I noticed the - and + next to Snapshot and Received.

Screen Shot 2019-06-15 at 3 45 59 PM

I mean, we're fine now, as this will forever be seared into our brains going forward, but it was _completely opposite_ compared to what we're all accustom to seeing in the dev world, like here on GitHub.

Was this page helpful?
0 / 5 - 0 ratings