Skip to content

Commit

Permalink
Wrap children result in an array if not already in one (dojo#844)
Browse files Browse the repository at this point in the history
* wrap children result in an array if not already in one

* add test for wrapped children
  • Loading branch information
tomdye committed Sep 23, 2020
1 parent 9c95ae1 commit 2c847ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/testing/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ export function assertion(renderFunc: () => DNode | DNode[]) {
const node = findNode(render, wrapped);
node.children = node.children || [];
let childrenResult = children();
if (!Array.isArray(childrenResult)) {
childrenResult = [childrenResult];
}
switch (type) {
case 'prepend':
node.children = [...childrenResult, ...node.children];
Expand Down
14 changes: 14 additions & 0 deletions tests/testing/unit/renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -758,5 +758,19 @@ describe('test renderer', () => {
))
);
});

it('Should wrap single children in an array when calling setChildren', () => {
const factory = create().children<string>();
const TestWidget = factory(() => 'foo');
const App = create()(() => {
return <TestWidget>bar</TestWidget>;
});
const WrappedTestWudget = wrap(TestWidget);

const testAssertion = assertion(() => <WrappedTestWudget>bar</WrappedTestWudget>);
const r = renderer(() => <App />);

r.expect(testAssertion.setChildren(WrappedTestWudget, () => 'bar'));
});
});
});

0 comments on commit 2c847ee

Please sign in to comment.