Skip to content

Closing bracket for JSX elements after new line in snapshots #2830

@chrisbujok

Description

@chrisbujok

Do you want to request a feature or report a bug?
Feature / Improvement.

What is the current behavior?
Currently React elements / components in snapshots have closing bracket in the same line as last prop, for example:

exports[`Foo bar 1`] = `
<foo
  a={true} />
`;

After adding another prop to foo, the test will fail and show diff like this:

- Snapshot
+ Received

@@ -1,2 +1,3 @@
 <foo
-  a={true} />
+  a={true}
+  b={true} />

What is the expected behavior?
In order to improve the clarity of diffs, move the closing bracket to a new line:

exports[`Foo bar 1`] = `
<foo
  a={true}
/>
`;

So the diff would be:

- Snapshot
+ Received

@@ -1,3 +1,4 @@
 <foo
   a={true}
+  b={true}
 />

So it'll only indicate that new line (with b={true}) has been added, without touching the prior line.
This will definitely break backward compatibility, but it should be easy to fix with --updateSnapshot option.

I'm looking forward to know your opinion. I'm happy to create a pull request with solution (I already have working PoC).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions