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

Configure serializer to skip element attributes on snapshot. #57

Closed
dzhytomyrsky opened this issue Apr 27, 2017 · 7 comments
Closed

Configure serializer to skip element attributes on snapshot. #57

dzhytomyrsky opened this issue Apr 27, 2017 · 7 comments

Comments

@dzhytomyrsky
Copy link

dzhytomyrsky commented Apr 27, 2017

Hello is it possible to configure serializer to skip element attributes? It would be wonderful to get on snapshot only elements and innerText.

<ul
  className="bottomMasked"
  id="agentsList"
  onScroll={[Function]}
>
  <li
    className={null}
    onClick={[Function]}
>
    Detective Inspector Lee
  </li>
</ul>
@runk
Copy link

runk commented Apr 28, 2017

Would be awesome to have this feature. 💯

@JonathanTR
Copy link

JonathanTR commented Aug 18, 2017

What would it look to configure this? Maybe something like?:

import serializer from 'enzyme-to-json/serializer';
import Foo        from './Foo'

const compactSerializer = serializer.withExceptions([<ul />, <Foo />]);
expect.addSnapshotSerializer(compactSerializer);

@adriantoine
Copy link
Owner

Hi!

Thanks for your suggestions, would you mind giving more details about that? I don't think I understand, you want a snapshot with only elements and inner texts?

enzyme-to-json is only converting Enzyme wrappers to a JSON format that is compatible with Jest snapshot testing. Isn't that something you want to be implemented in Jest so that it is available for people only using react-test-renderer?

@JonathanTR
Copy link

JonathanTR commented Aug 23, 2017

Ah, I'm realizing that what I wanted was actually quite different from OP, as I had read their post pretty quickly. What I was thinking was something more along the lines of being able to collapse certain elements within a snapshot.

So instead of having:

<Button
  color="blue"
>
  <button
    className="button blue"
  >
  </button>
</Button>

I could configure my serializer to just return something like:

<Button
  color="blue"
>
  { [children] }
</Button>

This would be awesome for cleaning up snapshots, especially in cases where there's lots of HOC's wrapped up in an implementation. Being able to configure whether I wanted inline props or not would be even more cool, so I could end up with a beautiful snapshot like:

<Button color="blue">
  { [children] }
</Button>

@adriantoine
Copy link
Owner

adriantoine commented Sep 18, 2017

I'm working on a map functionality (see #48) which would give much more control on the output. It will be released with v3.0.0.

I'm not sure about the details of the implementation but I'll give more details in #67 as soon as I can.

Thanks for your suggestions!

@adriantoine
Copy link
Owner

@JonathanTR @dzhytomyrsky @runk I just added a comment to #67 about this new mapping functionality, can you tell me if it solves your issue?

Thanks!

@adriantoine
Copy link
Owner

v3.0.0 has been released 🎉, the map functionality should cover this use case, if not, please comment on this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants