Skip to content

Using signals in render template should automatically apply to component #517

Open
@NateRadebaugh

Description

@NateRadebaugh

The closest I'm seeing is this example, but it has some issues:

https://github.com/testing-library/angular-testing-library/blob/main/apps/example-app/src/app/examples/22-signal-inputs.component.spec.ts

  1. Only model can be updated, which would require us to change our components from input for anything we want to test, which is not ideal
  2. Manually interacting with the underlying values like that is testing implementation details
  3. The template syntax in render doesn't expose an underlying componentRef to call setInput on

In an ideal world, the template will automatically update when the signal changes, like we'd expect in angular template HTML:

Preferred API:

  it("should render text from a signal", async () => {
    const someSignal = signal("hello");

    await render(
      html`<span data-testid="value">{{ someSignal() }} world</span>`,
      {
        componentProperties: {
          someSignal,
        },
      },
    );

    // Passes
    expect(screen.getByTestId("value")).toHaveTextContent("hello world");

    someSignal.set("updated");

    // Fails
    expect(screen.getByTestId("value")).toHaveTextContent("updated world");
  });

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