Skip to content

feat: testing directives #47

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 2 commits into from
Sep 18, 2019
Merged

feat: testing directives #47

merged 2 commits into from
Sep 18, 2019

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant