Skip to content

Implementation render directive #28

Closed

Description

@MRinaldi9

Thanks to the implementation of render function for component is possible to create a renderDirective that it will make possible to test attribute directives.
I thought something like this for the implementation that i think it will made this possible:

@Directive({
  selector: '[appHighlight]',
  host: {
    '[class]': 'className()',
    '(blur)': 'blurred.emit($event)',
  },
})
export class HighlightDirective {
  test = input.required<string>({ alias: 'appHighlight' });
  blurred = output<FocusEvent>();
}

renderDirective(HighlightDirective, {
    template: `<div [appHighlight]="color" (blurred)="onClick($event)">Test</div>`,
    hostProps: { color: 'red', onClick: vi.fn() },
 });

the upper implementation is a partial implementation derivative from this interface:

export interface DirectiveRenderOptions {
  /** Template to render the directive in. Must include the directive selector. */
  template: string;
  /** Host component input values to pass and make reactive. */
  hostProps?: Record<string, unknown>;
  /** Additional imports for the test host component */
  imports?: any[] | Type<any>[];
  /** Additional providers for the test module. */
  providers?: Provider[];
  /** The base element for screen queries. Defaults to document.body. */
  baseElement?: HTMLElement;
}

Activity

  1. shairez commented on Sep 16, 2026

    @shairez
    Contributor

    closing as a follow up on #29

    Thanks again for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions