]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(test-renderer): indent on multiple children
authorEvan You <yyx990803@gmail.com>
Mon, 1 Oct 2018 21:50:02 +0000 (17:50 -0400)
committerEvan You <yyx990803@gmail.com>
Mon, 1 Oct 2018 21:50:02 +0000 (17:50 -0400)
packages/renderer-test/__tests__/testRenderer.spec.ts
packages/renderer-test/src/serialize.ts

index f20777a0287ad2ef5a6f8846ae3471417cb6bedd..bb42ab66d61212d2fb0913c163569a8f25bd673b 100644 (file)
@@ -132,16 +132,21 @@ describe('test renderer', () => {
           {
             id: 'test'
           },
-          'hello'
+          [h('span', 'foo'), 'hello']
         )
       }
     }
     const root = nodeOps.createElement('div')
     render(h(App), root)
-    expect(serialize(root)).toEqual(`<div><div id="test">hello</div></div>`)
+    expect(serialize(root)).toEqual(
+      `<div><div id="test"><span>foo</span>hello</div></div>`
+    )
     expect(serialize(root, 2)).toEqual(
       `<div>
   <div id="test">
+    <span>
+      foo
+    </span>
     hello
   </div>
 </div>`
index ee75b87e29db90c7cdfce9d97d7de71e206d01d7..bfc91e66aec90254bfd8e4aadcebe8c996dbb2ae 100644 (file)
@@ -22,10 +22,11 @@ function serializeElement(
       return `${key}=${JSON.stringify(node.props[key])}`
     })
     .join(' ')
+  const newLine = indent ? `\n` : ``
   const children = node.children.length
-    ? (indent ? `\n` : ``) +
-      node.children.map(c => serialize(c, indent, depth + 1)) +
-      (indent ? `\n` : ``)
+    ? newLine +
+      node.children.map(c => serialize(c, indent, depth + 1)).join(newLine) +
+      newLine
     : ``
   const padding = indent ? ` `.repeat(indent).repeat(depth) : ``
   return (