Enzyme: add a parameter to prettify html output

Created on 30 Apr 2018  路  4Comments  路  Source: enzymejs/enzyme

I very often use html() to make a string that I pass to jest snapshoting method. Problem is I always need to import pretty package and wrap it in that because it just dumps the html on a single line. It would be helpful if I could jsut pass a true argument which would make the output span multiple lines. Is that something you'd be willing to merge if I made a PR?

this:
image

instead of:
image

Surely I could make my own toMatchPrettySnapshot test util function, but this issue will be prevalent in all testing libraries and frameworks, so if I'd have a project with ava instead of jest I'd just have to create another util.

feature request question

All 4 comments

I'd recommend using .debug() instead of .html() here, for a number of reasons.

I'm going to close, but am happy to reopen if there's still a feature you need.

Debug is not meant to be used on snapshot testing @ljharb. Or am I wrong ?

@carloscuesta that's true, but if you insist on doing (brittle, discouraged) snapshot testing, .debug() is the closest reliable thing enzyme provides for it.

Was this page helpful?
0 / 5 - 0 ratings