0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-11-30 00:46:29 +01:00

tweak htmlEqual helper so tests are easier to write

This commit is contained in:
Rich Harris 2017-03-16 16:10:00 -04:00
parent 8b3f0320f6
commit 2c4c7079e5

View File

@ -71,12 +71,8 @@ function cleanChildren ( node ) {
child.data = child.data.replace( /\s{2,}/, '\n' );
if ( child.data === '\n' ) {
node.removeChild( child );
}
// text
else if ( previous && previous.nodeType === 3 ) {
if ( previous && previous.nodeType === 3 ) {
previous.data += child.data;
previous.data = previous.data.replace( /\s{2,}/, '\n' );
@ -106,11 +102,11 @@ function cleanChildren ( node ) {
export function setupHtmlEqual () {
return env().then( window => {
assert.htmlEqual = ( actual, expected, message ) => {
window.document.body.innerHTML = actual.trim();
window.document.body.innerHTML = actual.replace( />[\s\r\n]+</g, '><' ).trim();
cleanChildren( window.document.body, '' );
actual = window.document.body.innerHTML;
window.document.body.innerHTML = expected.trim();
window.document.body.innerHTML = expected.replace( />[\s\r\n]+</g, '><' ).trim();
cleanChildren( window.document.body, '' );
expected = window.document.body.innerHTML;