Testing Harness - optional named children
- Dominant language
- TypeScript
- Stars
- 623
- Forks
- 78
- PR merge metrics
- No merged PRs in 30d
Description
**Bug**
Package Version:
**Code**
Given a widget where children are defined as matching an interface or being undefined and another widget that uses that widget, i am unable to set the children of the widget using the test harness as it throws an error relating to the children being optional:
```tsx
// Widgets
interface Children {
foo?: RenderResult;
bar?: (baz: string) => RenderResult;
}
const factory = create()
.children();
export const Widget = factory(function({
children
}) {
const [{ foo, bar } = { foo: undefined, bar: undefined }] = children();
return
{foo}
{bar('test')}
;
});
export const ParentWidget = factory(function() {
return {foo: 'test'}
})
```
```tsx
// Test
const WrappedWidget = wrap(Widget);
const baseAssertion = assertion(() => );
const r = renderer(() => );
r.child(WrappedWidget, { foo: [], bar: ['test'] });
```
I see the following error message (taken from actual usage involving the `RadioGroup`):
```
"Argument of type 'Wrapped; children: RadioGroupChildren; }>>' is not assignable to parameter of type 'Wrapped>'.\n Type 'Wrapped; children: RadioGroupChildren; }>>' is not assignable to type 'WNodeFactory<{ properties: any; children: any; }>'.\n Types of property 'type' are incompatible.\n Type '\"optional\"' is not assignable to type '\"required\"'.",
"source": "ts",
"startLineNumber": 83,
"startColumn": 11,
"endLineNumber": 83,
"endColumn": 28
}
```
**Expected behavior:**
I should be able to trigger these functions and test the output due to a type error.
**Actual behavior:**
I have to cast the `WrappedWidget` to `any` to get past the existing typings.
Contributor guide
Assessment
This issue has not been assessed yet.