getsaf / shallow-render

Angular testing made easy with shallow rendering and easy mocking. https://getsaf.github.io/shallow-render
MIT License
273 stars 25 forks source link

Shallow-render fails to bind @Input properties with required option in Angular 16 #255

Open lucaspaties opened 3 months ago

lucaspaties commented 3 months ago

Hello, I've encountered an issue when using shallow-render with Angular 16.

In Angular 16, @Input properties can have a required option. However, when I try to bind these properties in my tests, I get this: InvalidCharacterError: Failed to execute 'setAttribute' on 'Element': '[[object' is not a valid attribute name.

Ex:


import { Component, Input } from "@angular/core";

@Component({
    selector: "my-component",
    templateUrl: "./my-component.component.html"
})

export class MyComponent {
    @Input({ required: true }) myInput1: any;

}}

Then on the test file:

 const render = async () =>
     shallow
         .provideMock({ provide: Service, useValue: ServiceMock })
         .provideMock({ provide: Toastr, useValue: ToastrMock })
         .render({ bind: { myInput1: objectMock } });

Can you look into it?