From f85349e13df5c2f6282b7ed73162049074dfe19a Mon Sep 17 00:00:00 2001 From: Bradley Maier Date: Tue, 8 Sep 2020 18:02:48 -0700 Subject: [PATCH 1/2] Handle falsy children in decorate --- src/testing/decorate.ts | 4 +++- tests/testing/unit/renderer.tsx | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/testing/decorate.ts b/src/testing/decorate.ts index a600441a5..a61801686 100644 --- a/src/testing/decorate.ts +++ b/src/testing/decorate.ts @@ -66,7 +66,9 @@ export function decorate(actual: RenderResult, expected: RenderResult, instructi let node = nodes.shift(); while (node) { - const [actualNodes, expectedNodes] = node; + const [actualNodes, expectedNodes] = node.map((nodes) => + nodes.filter((node) => node != null && node !== true && node !== false) + ); let childNodes: DecorateTuple[] = []; while (expectedNodes.length > 0) { let actualNode: DNode | { [index: string]: any } = actualNodes.shift(); diff --git a/tests/testing/unit/renderer.tsx b/tests/testing/unit/renderer.tsx index 14497a4e2..43015f130 100644 --- a/tests/testing/unit/renderer.tsx +++ b/tests/testing/unit/renderer.tsx @@ -14,6 +14,23 @@ const noop: any = () => {}; class ChildWidget extends WidgetBase<{ id: string; func?: () => void }> {} +const ConditionalRender = create({ icache })(({ middleware: { icache } }) => { + return v('div', {}, [ + icache.get('render') + ? v('div', { + onclick: () => { + icache.set('render', false); + } + }) + : null, + v('div', { + onclick: () => { + icache.set('render', true); + } + }) + ]); +}); + class MyWidget extends WidgetBase { _count = 0; _result = 'result'; @@ -222,6 +239,19 @@ describe('test renderer', () => { ); }); + it('trigger property when there are undefined children in actual render', () => { + const WrappedRoot = wrap('div'); + const WrappedChild = wrap('div'); + const WrappedConditional = wrap('div'); + const baseTemplate = assertion(() => w(WrappedRoot, {}, [w(WrappedChild, { onclick: noop })])); + const r = renderer(() => w(ConditionalRender, {})); + r.expect(baseTemplate); + r.property(WrappedChild, 'onclick'); + r.expect(baseTemplate.prepend(WrappedRoot, () => [w(WrappedConditional, { onclick: noop })])); + r.property(WrappedConditional, 'onclick'); + r.expect(baseTemplate); + }); + it('should call properties in the correct order', () => { const factory = create({ icache }); From 5eaa6c31bace57c1dfc6d0e9b1773349bb68ba9a Mon Sep 17 00:00:00 2001 From: Bradley Maier Date: Wed, 9 Sep 2020 09:02:29 -0700 Subject: [PATCH 2/2] PR feedback --- tests/testing/unit/renderer.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/testing/unit/renderer.tsx b/tests/testing/unit/renderer.tsx index 43015f130..1071eb84b 100644 --- a/tests/testing/unit/renderer.tsx +++ b/tests/testing/unit/renderer.tsx @@ -239,15 +239,15 @@ describe('test renderer', () => { ); }); - it('trigger property when there are undefined children in actual render', () => { + it('triggers property when there are undefined children in actual render', () => { const WrappedRoot = wrap('div'); const WrappedChild = wrap('div'); const WrappedConditional = wrap('div'); - const baseTemplate = assertion(() => w(WrappedRoot, {}, [w(WrappedChild, { onclick: noop })])); + const baseTemplate = assertion(() => v(WrappedRoot.tag, {}, [v(WrappedChild.tag, { onclick: noop })])); const r = renderer(() => w(ConditionalRender, {})); r.expect(baseTemplate); r.property(WrappedChild, 'onclick'); - r.expect(baseTemplate.prepend(WrappedRoot, () => [w(WrappedConditional, { onclick: noop })])); + r.expect(baseTemplate.prepend(WrappedRoot, () => [v(WrappedConditional.tag, { onclick: noop })])); r.property(WrappedConditional, 'onclick'); r.expect(baseTemplate); });