Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing Harness - optional named children #836

Open
tomdye opened this issue Sep 8, 2020 · 0 comments
Open

Testing Harness - optional named children #836

tomdye opened this issue Sep 8, 2020 · 0 comments
Labels
area: testing Testing bug Something isn't working

Comments

@tomdye
Copy link
Member

tomdye commented Sep 8, 2020

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.

@tomdye tomdye added area: testing Testing bug Something isn't working labels Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: testing Testing bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant