-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Bug: Angular 17.1.0 input.required()
issues
#7976
Comments
|
It looks like, at the moment, Angular themselves test out signal inputs by manually defining and using wrapper components (i.e. without any reflection on the available inputs and types): |
Any news about this issue ? |
Potentially useful: the Spectator library is being updated to support signal inputs: ngneat/spectator#638 |
Seems to me like this can be regarded as resolved. For comparison, this is @Sebastian-G 's stackblitz with This is the same stackblitz with TL;DR: Update jest-preset-angular or dependencies that use jest-preset-angular |
How about when using Jasmine? (The default out-of-the-box experience that Angular provides) |
Fair enough, my comment was jest-centric. I have no idea about jasmine |
@cuddlecake — it's useful to know, thanks for sharing. Aside: Angular does have official experimental support for Jest; I wonder where that will go. |
Not sure if this is a seperate issue or related, but I'm getting import { CommonModule } from '@angular/common';
import { Component, NgModule, input } from '@angular/core';
import { MockBuilder, MockRender } from 'ng-mocks';
@Component({
selector: 'signal-component',
template: '<h1>{{ header() }}</h1>',
})
class SignalComponent {
public readonly header = input<string>();
}
@Component({
selector: 'target-component',
template: '<signal-component [header]="hello"></signal-component>',
})
class TargetComponent {
public readonly hello = 'Hello!';
}
@NgModule({
declarations: [TargetComponent, SignalComponent],
imports: [CommonModule],
})
class TargetModule {}
describe('signal inputs', () => {
beforeEach(() => MockBuilder(TargetComponent, TargetModule));
it('should be created', () => {
expect(
MockRender(TargetComponent)?.point?.componentInstance,
).toBeTruthy();
});
}); |
I believe it might be a good idea to migrate to Do you have any input @satanTime? |
Hi @andreandersson, it used to be like that, but it doesn't represent all the data which is needed for mocks, that's why |
Done some digging. This probably relates to angular/angular#54013 For example, this does not work in ng-mocks, but in a new Angular-repository:
|
Adds a custom transformer to transform Angular Code, specifically, signals (input, query and models) to behave better in jit-environment. Solves help-me-mom#7976
Adds a custom transformer to transform Angular Code, specifically, signals (input, query and models) to behave better in jit-environment. Solves help-me-mom#7976
Adds a custom transformer to transform Angular Code, specifically, signals (input, query and models) to behave better in jit-environment. Solves help-me-mom#7976
I've noticed that Signal Inputs are just treated as Decorator Input. I have the following component: @Component({
selector: 'app-list-item',
standalone: true,
templateUrl: './list-item.component.html',
styleUrl: './list-item.component.scss',
})
export class ListItemComponent {
task = input.required<Task>();
} I mock the component using MockComponent function: await TestBed.configureTestingModule({
imports: [ListComponent],
providers: [
{
provide: TasksService,
useValue: tasksServiceStub,
},
],
})
.overrideComponent(ListComponent, {
remove: {
imports: [ListItemComponent],
},
add: {
imports: [MockComponent(ListItemComponent)], // I mock here
},
})
.compileComponents(); And my test try to access the Singal Input from expect((<ListItemComponent>item.componentInstance).task()).toEqual(completedTasksStub[index]); But the test breaks because the The complete error: Logging the
Working with Signal Inputs, we need to test it as a Signal and not as a property as it was with Decorator Inputs. Any news about that @satanTime? Thank for your amazing work btw |
I just created an issue related to my last comment |
Adds a custom transformer to transform Angular Code, specifically, signals (input, query and models) to behave better in jit-environment. Solves help-me-mom#7976
Adds a custom transformer to transform Angular Code, specifically, signals (input, query and models) to behave better in jit-environment. Solves help-me-mom#7976
Adds a custom transformer to transform Angular Code, specifically, signals (input, query and models) to behave better in jit-environment. Solves help-me-mom#7976 Signed-off-by: André Andersson <[email protected]>
This works: import { ChangeDetectionStrategy, Component, input } from '@angular/core';
@Component({
selector: 'app-banner',
standalone: true,
imports: [],
templateUrl: './banner.component.html',
styleUrl: './banner.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class BannerComponent {
title = input.required<string>();
} import { MockBuilder, MockRender } from 'ng-mocks';
import { I18nTestingModule } from '@/i18n/i18n.testing.module';
import { BannerComponent } from './banner.component';
describe('BannerComponent', () => {
async function setup() {
await MockBuilder(BannerComponent).keep(I18nTestingModule);
return MockRender(BannerComponent, { title: 'Hello World' }); // set your input here (it does not seem to be typed btw)
}
it('should create', async () => {
const fixture = await setup();
expect(fixture.point.componentInstance).toBeTruthy();
});
}); |
Description of the bug
After upgrading Angular to 17.1.0 and using
input.required()
, my tests are broken.see
It seems like it is not possible to use the
MockRenderer
to initialize the component anymore:An example of the bug
Link:
https://stackblitz.com/edit/ex-base-reusable-component-epbxhj?file=src%2Fapp%2Fuser-profile-card%2Fuser-profile-card.component.spec.ts
RUN
npm test
to see the error.Expected vs actual behavior
All tests should run through.
There should be no difference between
@Input()
and theinput
function.As you can see it is working as expected on
npm start
.The text was updated successfully, but these errors were encountered: