You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<div><h3class="inline-block">Create New and Spinner</h3><span><iclass="fa fa-spinner fa-pulse fa-lg fa-fw"></i><spanclass="sr-only">Loading...</span></span><a><buttontype="button" class="primary"><iclass="fa fa-plus"></i>
Create New
</button></a></div>
If you change the options passed into pretty, you can get this:
<div><h3class="inline-block">Create New and Spinner</h3><span><iclass="fa fa-spinner fa-pulse fa-lg fa-fw"></i><spanclass="sr-only">Loading...</span></span><a><buttontype="button" class="primary"><iclass="fa fa-plus"></i>
Create New
</button></a></div>
Here is a comparison of a diff generated using the default jest-serializer-vue and my custom options.
Note: This is for a simple, 25 line, template. Imagine a longer, more complex diff, like in a table component with lots of rows of data that have custom markup logic in each cell.
I've changed the serializer on all my projects to a custom one, based on jest-serializer-vue to have these easier to read snapshots.
// Based on jest-serializer-vueconstbeautify=require('pretty');functionisHtmlString(received){returnreceived&&typeof(received)==='string'&&received.startsWith('<');}functionisVueWrapper(received){returnreceived&&typeof(received)==='object'&&typeof(received.isVueInstance)==='function';}functionremoveServerRenderedText(html){returnhtml.replace(/data-server-rendered="true"/,'');}// This removes data-test="whatever" from your snapshots// If you also want to remove them from your production builds, see:// https://forum.vuejs.org/t/how-to-remove-attributes-from-tags-inside-vue-components/24138functionremoveDataTestAttributes(html){// [-\w]+ will catch 1 or more instaces of a-z, A-Z, 0-9, hyphen (-), or underscore (_)returnhtml.replace(/data-test="[-\w]+"/g,'');}module.exports={test: function(received){returnisHtmlString(received)||isVueWrapper(received);},print: function(received){lethtml=received||'';if(isVueWrapper(received)){html=received.html();}html=removeServerRenderedText(html);html=removeDataTestAttributes(html);// To see available options: https://github.com/beautify-web/js-beautify/blob/master/js/src/html/options.jsconstoptions={indent_char: ' ',indent_inner_html: true,indent_size: 2,inline: [],sep: '\n',unformatted: ['code','pre']};returnbeautify(html,options);}};
Adopting the same options in the official jest-serializer-vue will have much better default snapshots (though will break people's existing snapshots, so it should be a major bump if adopted). Though I would find it preferable to make these options modifiable in some way, so user's can tweak them without having to basically duplicate the same file, losing downstream updates, just to change an option. And from the other perspective it would allow people to opt out of changes in these options in the future by passing in their own overrides if they change again, making breaking changes of the future less painful.
The text was updated successfully, but these errors were encountered:
The default options shipped in
jest-serializer-vue
make snapshots and snapshot diffs pretty unreadable half the time.Input code like this:
Will output code like this:
If you change the options passed into
pretty
, you can get this:Here is a comparison of a diff generated using the default
jest-serializer-vue
and my custom options.Note: This is for a simple, 25 line, template. Imagine a longer, more complex diff, like in a table component with lots of rows of data that have custom markup logic in each cell.
I've changed the serializer on all my projects to a custom one, based on
jest-serializer-vue
to have these easier to read snapshots.Adopting the same options in the official
jest-serializer-vue
will have much better default snapshots (though will break people's existing snapshots, so it should be a major bump if adopted). Though I would find it preferable to make these options modifiable in some way, so user's can tweak them without having to basically duplicate the same file, losing downstream updates, just to change an option. And from the other perspective it would allow people to opt out of changes in these options in the future by passing in their own overrides if they change again, making breaking changes of the future less painful.The text was updated successfully, but these errors were encountered: