-
Notifications
You must be signed in to change notification settings - Fork 91
feat(testing-library): add an overload for template rendering #206
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
feat(testing-library): add an overload for template rendering #206
Conversation
644c9bd
to
f634d36
Compare
@@ -176,7 +191,7 @@ export async function render<SutType, WrapperType = SutType>( | |||
detectChanges, | |||
navigate, | |||
rerender, | |||
debugElement: fixture.debugElement.query(By.directive(sut)), | |||
debugElement: typeof sut === 'string' ? fixture.debugElement : fixture.debugElement.query(By.directive(sut)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an only difference between render(directive, { template })
and render(template)
. Is it acceptable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this fine.
* }) | ||
*/ | ||
wrapper?: Type<WrapperType>; | ||
componentProperties?: Partial<WrapperType & Properties>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have an opinion about the naming of componentProperties
?
Should it be better to name this wrapperComponentProperties
or hostComponentProperties
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like wrapperComponentProperties
which has consistency with wrapper
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I think it is hard to change the name now. Because RenderComponentOptions
and RenderDirectiveOptions
still has componentProperties
, making overload with co-existing these are complex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking of two options.
Option 1. Just properties
or props
in all type of render
options
Vue or other families are adopting that. And it is not relevant directly, Storybook for Angular has also a similar API. This option brings breaking change for the entire package but the result is simple.
https://storybook.js.org/docs/angular/writing-stories/introduction
export default {
title: 'Components/Button',
component: Button,
} as Meta;
export const Primary = () => ({
props: {
label: 'Button',
background: '#ff0',
},
});
Option 2. Extending wrapper
for passing wrapper component properties. Implementation for this is more complex than Option 1.
{
wrapper: {
component: WrapperComponent,
properties: { ... }
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like option 1, and you're (again) totally right.
Let's leave it with componentProperties, and we might rename that in a next breaking version.
I won't do it know, just because this is a minor difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @lacolaco , I added one question about naming a property.
The rest is 👍👍.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your ideas and the implementation!
@all-contributors please add @lacolaco for code, ideas |
I've put up a pull request to add @lacolaco! 🎉 |
🎉 This PR is included in version 10.6.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Close #203
render(template: string, options: RenderTemplateOptions)
overloadrender(directive, { template })
directives.spec.ts
torender-template.spec.ts
I believe this change won't break existing tests as long as users aren't restricting
@deprecated
API usage.