Skip to content

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

Merged
merged 1 commit into from
Apr 22, 2021

Conversation

lacolaco
Copy link
Contributor

@lacolaco lacolaco commented Apr 22, 2021

Close #203

  • Add render(template: string, options: RenderTemplateOptions) overload
  • Deprecate render(directive, { template })
  • Rename directives.spec.ts to render-template.spec.ts
  • Update specs and examples to the new signature
    • Single spec is left for validating backward-compatibility

I believe this change won't break existing tests as long as users aren't restricting @deprecated API usage.

@@ -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)),
Copy link
Contributor Author

@lacolaco lacolaco Apr 22, 2021

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?

Copy link
Member

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>;
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

@lacolaco lacolaco Apr 22, 2021

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: { ... }
  }
}

Copy link
Member

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.

Copy link
Member

@timdeschryver timdeschryver left a 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 👍👍.

Copy link
Member

@timdeschryver timdeschryver left a 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!

@timdeschryver timdeschryver merged commit 5f72ebf into testing-library:master Apr 22, 2021
@timdeschryver
Copy link
Member

@all-contributors please add @lacolaco for code, ideas

@allcontributors
Copy link
Contributor

@timdeschryver

I've put up a pull request to add @lacolaco! 🎉

@github-actions
Copy link

🎉 This PR is included in version 10.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Request: Add template to RenderComponentOptions
2 participants