Skip to content

Commit 2c847ee

Browse files
committed
Wrap children result in an array if not already in one (dojo#844)
* wrap children result in an array if not already in one * add test for wrapped children
1 parent 9c95ae1 commit 2c847ee

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/testing/renderer.ts

+3
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ export function assertion(renderFunc: () => DNode | DNode[]) {
280280
const node = findNode(render, wrapped);
281281
node.children = node.children || [];
282282
let childrenResult = children();
283+
if (!Array.isArray(childrenResult)) {
284+
childrenResult = [childrenResult];
285+
}
283286
switch (type) {
284287
case 'prepend':
285288
node.children = [...childrenResult, ...node.children];

tests/testing/unit/renderer.tsx

+14
Original file line numberDiff line numberDiff line change
@@ -758,5 +758,19 @@ describe('test renderer', () => {
758758
))
759759
);
760760
});
761+
762+
it('Should wrap single children in an array when calling setChildren', () => {
763+
const factory = create().children<string>();
764+
const TestWidget = factory(() => 'foo');
765+
const App = create()(() => {
766+
return <TestWidget>bar</TestWidget>;
767+
});
768+
const WrappedTestWudget = wrap(TestWidget);
769+
770+
const testAssertion = assertion(() => <WrappedTestWudget>bar</WrappedTestWudget>);
771+
const r = renderer(() => <App />);
772+
773+
r.expect(testAssertion.setChildren(WrappedTestWudget, () => 'bar'));
774+
});
761775
});
762776
});

0 commit comments

Comments
 (0)