Vue-test-utils: Pretty-print html() output by default

Created on 13 Feb 2019  路  10Comments  路  Source: vuejs/vue-test-utils

What problem does this feature solve?

My team is using @vue/test-utils for snapshot testing components but the snapshots are hard to parse because the HTML string output from .html() is not formatted in a readable way. If html() pretty-printed the HTML it would be a lot easier to review changes to the component-generated HTML.

What does the proposed API look like?

html() would pretty-print the returned HTML string by default, perhaps using something like https://github.com/prettydiff/prettydiff. If necessary, a user could bypass pretty-printing by passing an option to .html(), perhaps .html(false) or .html({ prettyPrint: false }).

feature request

Most helpful comment

For snapshot tests, I recommend using the DOM element:

expect(wrapper.element).toMatchSnapshot()

All 10 comments

For snapshot tests, I recommend using the DOM element:

expect(wrapper.element).toMatchSnapshot()

Thank you for your recommendation Edd. I'm sorry that I forgot to mention that I'm mounting/testing the components in Chrome with Puppeteer using page.evaluate so the return value (which then gets its snapshot taken) has to be serializable.

I think you can just use diffable-html in your tests

I needed this too in my test! @eddyerburgh if anyone isn't actively looking into this, I'm interested to work on this, but I guess we might have to agree on the API, whether it's .html(true | false) or .html({ prettyPrint: true | false }).

@briwa @eddyerburgh I have a tentative Pull Request for this feature. Are there any preferences on .html(bool) vs .html({ prettyPrint: bool })?

@addisonssense I'd vote for .html(pretty = false) but let's hear it from the majority.

I prefer html({ prettyPrint: true | false }) in case we add extra options in the future

I have created a PR to resolve this issue. I welcome feedback :)
https://github.com/vuejs/vue-test-utils/pull/1229

Thinking about it more, I think it should pretty print by default. Vue Test Utils is still in beta so we can make breaking changes now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eddyerburgh picture eddyerburgh  路  4Comments

caugner picture caugner  路  3Comments

matt-sanders picture matt-sanders  路  3Comments

vilarinholeo picture vilarinholeo  路  3Comments

jonyoder picture jonyoder  路  3Comments