Skip to content

Feature Request: sensible signal input handling for MockRender(Component) / DefaultRenderComponent #14003

Description

@daniel-sc

Describe the feature or problem you'd like to solve

When using MockRender(Component) the params take input signals as-is, which breaks usage.

Example:

@Component()
export class MyComponent {
  myInput = input<string>(null);
}

const params = MockRender(MyComponent).componentInstance;
// p has type `{myInput: InputSignal<string>}`

The sensible type would be:

const params = MockRender(MyComponent).componentInstance;
// p has type `{myInput: string | undefined}`

Proposed solution

DefaultRenderComponent could be extended like this:

import type { InputSignalWithTransform } from '@angular/core';  
  
type InputBindingType<T> =  
	T extends InputSignalWithTransform<any, infer WriteT>  
	? WriteT  
	: T;  
  
export type DefaultRenderComponent<MComponent> = {  
	[K in keyof MComponent]: InputBindingType<MComponent[K]>;  
};

Breaking Change

Of course, technically, this would be a breaking change, but I think this is what every user would expect anyways. Also the old type (probably) did not really work, as assigning an singal instance to a signal input does not make sense.

Additional context

Relevant docs:

When MockRender(Component) is used without params then fixture.componentInstance controls @inputs and @outputs of the component. That lets it trigger the correct lifecycle hooks.

This then could be updated to

When MockRender(Component) is used without params then fixture.componentInstance controls @inputs and @outputs of the component. That lets it trigger the correct lifecycle hooks. For signal inputs it automatically uses the binding/write type.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions