-
-
Notifications
You must be signed in to change notification settings - Fork 177
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
Cannot pass props which are not input() type in createComponent() #650
Comments
In the previous version, we could also provide via the props the input despite its alias name. @Component({ ... })
export class XyzComponent {
name = input('userName');
} spectator = createComponent({
props: {
name: 'John Doe'
},
}); In 17.1.0 this is not working and we have to provide the input using |
Hi @ashutoshpaul! I think the current behavior is valid - it's still possible to edit fields by doing something like: const spectator = createComponent();
spectator.component.age = 12;
spectator.component.id = 13; The reason I believe the current behavior is correct, is that only input fields (IE: fields marked with This simulates Angular's own behaviour, where you wouldn't be able to do something like this:
Angular throws an error for this code as Now, while I strongly believe that we should only test a component's public API surface, I do see the possible utility in a way to assign values to non-input class fields. It depends mostly on how opinionated this library should be about best practices for Angular components. |
Agree with this statement |
Maybe we should change props to inputs? |
This sounds like a great idea. |
It'll be better to deprecate the props field for now and introduce the inputs field |
For better clarity lets assume theirs a
XyzComponent
In ngneat/spectator v16 we had:
and now in v17 we have:
As we can see earlier props was of type
Partial<C>
so we could pass values to component properties likeage
andid
in this way:but now since
props
is of typeInferInputSignals<C>
we can no longer pass values likeage
andid
but can only pass input() type variable values (eg.name
).Is there any way to pass/assign values to props which are not input() type?
The text was updated successfully, but these errors were encountered: