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

Pretty format mounted html #649

Closed
MayasHaddad opened this issue Nov 2, 2016 · 10 comments
Closed

Pretty format mounted html #649

MayasHaddad opened this issue Nov 2, 2016 · 10 comments

Comments

@MayasHaddad
Copy link

I am using jest and this code works good

    const wrapper = mount(<FancyComponent />)
    expect(wrapper.html()).toMatchSnapshot()
    wrapper.unmount()

except that I want the generated snapshot to be multiline, indented html.

Quite like this without having to use tools like enzyme-to-json

Any clue?

@ismay
Copy link

ismay commented Dec 9, 2016

I think it would be great if this were part of enzyme. Currently enzyme-to-json provides this functionality, but it breaks when coverage testing. react-test-renderer doesn't break when coverage testing, but doesn't provide the nice enzyme api.

So currently there's no good solution when you want to use enzyme and do coverage testing. So +1 for adding this to enzyme.

@ljharb
Copy link
Member

ljharb commented Dec 9, 2016

In general snapshot testing makes your tests more brittle - I'm not sure it's a good idea to make it more pleasant/easier to use it.

@ismay
Copy link

ismay commented Dec 9, 2016

Is there any objective evidence for that?

@ljharb
Copy link
Member

ljharb commented Dec 9, 2016

I have lots of anecdotal experience with it - what happens is that it's not explicit and thus clear what is being tested - ie, what's important - and then, when someone changes something that breaks the snapshot by design, it's very very easy to just check in the new snapshot, and not notice that an unrelated thing you changed broke.

Explicit tests take longer to write, but they're much harder for humans to unintentionally ignore failures with.

@ismay
Copy link

ismay commented Dec 9, 2016

Hmm ok. Yeah I can see how that would be problematic. I like using them for more presentational components. Especially the ones that change a lot in structure but still fulfill the same function, where function isn't easily expressed in a test. It's easier for me to check the snapshot than write a test that pretty much describes the markup.

@blainekasten
Copy link
Contributor

@MayasHaddad @ismay fwiw, I'm bringing this functionality into jest-enzyme. It doesn't belong on enzyme itself.

@ismay
Copy link

ismay commented Dec 12, 2016

Cool! 👍

@nathan5x

This comment has been minimized.

@ljharb

This comment has been minimized.

@nathan5x

This comment has been minimized.

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

5 participants