framework
framework copied to clipboard
Testing Harness - optional named children
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:
// Widgets
interface Children {
foo?: RenderResult;
bar?: (baz: string) => RenderResult;
}
const factory = create()
.children<Children | undefined>();
export const Widget = factory(function({
children
}) {
const [{ foo, bar } = { foo: undefined, bar: undefined }] = children();
return <virtual>
{foo}
{bar('test')}
</virtual>;
});
export const ParentWidget = factory(function() {
return <Widget key='test'>{foo: 'test'}</Widget>
})
// Test
const WrappedWidget = wrap(Widget);
const baseAssertion = assertion(() => <WrappedWidget key='test'></WrappedWidget>);
const r = renderer(() => <ParentWidget />);
r.child(WrappedWidget, { foo: [], bar: ['test'] });
I see the following error message (taken from actual usage involving the RadioGroup):
"Argument of type 'Wrapped<OptionalWNodeFactory<{ properties: Comparable<RadioGroupProperties & WidgetProperties & ThemeProperties>; children: RadioGroupChildren; }>>' is not assignable to parameter of type 'Wrapped<WNodeFactory<{ properties: any; children: any; }>>'.\n Type 'Wrapped<OptionalWNodeFactory<{ properties: Comparable<RadioGroupProperties & WidgetProperties & ThemeProperties>; 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.