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..1071eb84b 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('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(() => 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, () => [v(WrappedConditional.tag, { onclick: noop })])); + r.property(WrappedConditional, 'onclick'); + r.expect(baseTemplate); + }); + it('should call properties in the correct order', () => { const factory = create({ icache });