Enzyme: Pretty format mounted html

Created on 2 Nov 2016  路  10Comments  路  Source: enzymejs/enzyme

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?

enhancement question

Most helpful comment

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.

All 10 comments

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.

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.

Is there any objective evidence for that?

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.

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.

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

Cool! 馃憤

Any updates on this? Thanks!

@nathan5x there never will be any updates here; see https://github.com/enzymejs/enzyme/issues/649#issuecomment-266483678

Thanks @ljharb 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

blainekasten picture blainekasten  路  3Comments

thurt picture thurt  路  3Comments

abe903 picture abe903  路  3Comments

heikkimu picture heikkimu  路  3Comments

nelsonchen90 picture nelsonchen90  路  3Comments