From 3fe047b4accfcd013d4954484be61a94918e9456 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 1 Oct 2018 17:50:02 -0400 Subject: [PATCH] fix(test-renderer): indent on multiple children --- packages/renderer-test/__tests__/testRenderer.spec.ts | 9 +++++++-- packages/renderer-test/src/serialize.ts | 7 ++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/renderer-test/__tests__/testRenderer.spec.ts b/packages/renderer-test/__tests__/testRenderer.spec.ts index f20777a0..bb42ab66 100644 --- a/packages/renderer-test/__tests__/testRenderer.spec.ts +++ b/packages/renderer-test/__tests__/testRenderer.spec.ts @@ -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(`
hello
`) + expect(serialize(root)).toEqual( + `
foohello
` + ) expect(serialize(root, 2)).toEqual( `
+ + foo + hello
` diff --git a/packages/renderer-test/src/serialize.ts b/packages/renderer-test/src/serialize.ts index ee75b87e..bfc91e66 100644 --- a/packages/renderer-test/src/serialize.ts +++ b/packages/renderer-test/src/serialize.ts @@ -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 (