Skip to content

Conversation

timdeschryver
Copy link
Member

@timdeschryver timdeschryver commented Sep 9, 2019

This PR allows us to test directives by defining a template.
The template will be used to set the WrapperComponents's template, it's also possible to define a custom wrapper component.

It also introduces a DebugElement in the result to for easy access to the directive.
The fixture returned in case of a directive test, would be the wrapper component.

test('it is possible to test directives', async () => { const component = await render(SpoilerDirective, { template: `<div spoiler></div>`, }); }); test('it is possible to test directives with props', async () => { const hidden = 'SPOILER ALERT'; const visible = 'There is nothing to see here ...'; const component = await render(SpoilerDirective, { template: `<div spoiler [hidden]="hidden" [visible]="visible"></div>`, componentProperties: { hidden, visible, }, }); });

This introduces a couple of breaking changes:

  • The signature where you could define your component via the template syntax has been removed.

BEFORE:

const component = render(`<person-details></person-details>`)

AFTER:

const component = render(PersonDetails)
  • It isn't possible anymore to define a wrapper while testing components, I haven't found a good use case to allow this.
const component = render(PersonDetails, { wrapper: PersonWrapper })
@timdeschryver timdeschryver merged commit 6fa8df9 into master Sep 18, 2019
@timdeschryver timdeschryver deleted the directive-testing branch September 18, 2019 18:49
@timdeschryver
Copy link
Member Author

🎉 This PR is included in version 8.0.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

1 participant