-
-
Notifications
You must be signed in to change notification settings - Fork 181
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
Add support for input signals #637
Comments
We need to change the internal setInput to use the component ref setInput method and everything should work. Regarding the types, we can improve it. You're welcome to create a PR. |
Thanks for your response @NetanelBasal! I believe I can get something (mostly) ready but will be blocked by thymikee/jest-preset-angular#2255 as One thing As I'd love an implementation like this: export function setProps(componentRef: ComponentRef<T>, keyOrKeyValues: any, value?: any): any {
if (isString(keyOrKeyValues)) {
componentRef.setInput(keyOrKeyValues, value);
} else {
// eslint-disable-next-line guard-for-in
for (const p in keyOrKeyValues) {
componentRef.setInput(p, keyOrKeyValues[p]);
}
}
return componentRef.instance;
} But this would necessitate changes in the |
I feel like the |
I don't mind to introduce a breaking change. What do u have in mind? |
At the moment, we can set inputs in two ways with This could be confusing, as I can do the following in code: const spectator = createHost(`<div> <my-component [show]="show" /> </div>`);
// Two ways to set the same input, could be confusing
spectator.setHostProps({ show: false });
spectator.setProps({ show: true }); I propose removing Ideally this type of breaking change is something we want to avoid, but I'm not sure how to keep the API intact and support input signals for |
I agree that it's not the normal flow to call |
I added this functionality in #638 which works (all tests are passing locally) but there's some cleanup needed in related types + docs. Let me know what you think & I can take these up! |
sorry to but in, but you can already test signalInputs ? I've written some tests the other day with them, and currently you can just do something like: describe('text', () => {
it('should use the text input for the anchors text content', () => {
const text = input('our link text');
spectator.setInput('text', text);
spectator.detectChanges();
expect(spectator.query('a')).toHaveText(text());
});
}); and it seems to be fine |
@chocosd but in your example the original signal input is overridden, which may break the original default behaviour |
What @twittwer said indeed 😄 the changes from PR basically allow us to use Angular's own This allows us to stay a bit closer to So while technically assigning a new |
I'll close this atm as #638 got merged - if there happen to be any issues with these changes, or |
@kfrancois should it also work having a transformer defined, hence having something like this:
|
I am also experiencing problems for:
It seems that this problem only occurs having the input named "data". |
@kfrancois test fails if the input signal transforms the value to another type. |
Description
Angular 17.1 introduced input signals, which aren't supported yet by a few tools as the feature is quite new.
I've done some initial investigation in how to address this in
@ngneat/spectator
(seeProposed solution
below) but mainly want to know what the maintainers' plans are when it comes to supporting input signals, and how I could help out.We use Spectator pretty heavily and as testing is important, I'd love to be able to use Spectator for components that use input signals 😄
Proposed solution
A simple component using input signals could look like this:
This affects Spectator in two ways:
1. The type of inputs now needs to be inferred when the input is an input signal
When testing the above component, we want to do something like this:
Because Spectator does not know about input signals yet, Typescript will throw an error:
Type 'boolean' is not assignable to type 'InputSignal<boolean, boolean>'.
Fixing this is pretty simple, we can create a type like this to conditionally infer a signal's type:
2. Setting input signals is not the same as setting regular inputs
I'm not quite sure how to handle this as I haven't dug into the Angular source code enough to know how signals/input signals work under the hood.
Spectator's
setProps
function currently sets the following when changing inputs/props:I'm not sure whether a simple check like this would suffice:
I'm assuming the above code will not work as intended in all cases. This is where I'm looking for some feedback/help.
Alternatives considered
fixture.componentInstance.show
somehow)Do you want to create a pull request?
Yes
The text was updated successfully, but these errors were encountered: