Skip to content
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

MockComponent function set Signal Inputs as Decorator Inputs #8887

Open
henriquecustodia opened this issue May 3, 2024 · 2 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@henriquecustodia
Copy link

I've noticed that Signal Inputs are just treated as Decorator Input.

ng-mocks@14.12.2

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 ListItemComponent to assert its value:

 expect((<ListItemComponent>item.componentInstance).task()).toEqual(completedTasksStub[index]);

But the test breaks because the task property (it's a Signal Input) is not a function.

The complete error:
TypeError: completedItemDebugEl.componentInstance.task is not a function

Logging the <ListItemComponent>item.componentInstance).task in the test, I see that it's a property

task: { id: '1', name: 'Buy milk', completed: true }

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

@henriquecustodia henriquecustodia added the bug Something isn't working label May 3, 2024
@henriquecustodia henriquecustodia changed the title Bug: MockComponents set Signal Inputs as Decorator Inputs May 3, 2024
@henriquecustodia henriquecustodia changed the title MockComponents set Signal Inputs as Decorator Inputs MockComponent function set Signal Inputs as Decorator Inputs May 3, 2024
@gvlekke
Copy link

gvlekke commented Aug 6, 2024

any news if this will be picked up?

@teowgh
Copy link

teowgh commented Oct 22, 2024

Anyone working on it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants