angularangular17angular-signals

Signal input is not detected in component-module test


I develop project based on angular modules (ng17.1.3). I tried switching to signals from RxJS so I changed standard input (Input()) to signal input function. Component works fine but test crashes due to

Can't set value of the 'data' input on the 'XComponent' component. Make sure that the 'data' property is annotated with @Input() or a mapped @Input('data') exists.

XComponent:

@Component({
  selector: 'x-collection',
  templateUrl: './x-collection.component.html',
})
export class XCollectionComponent {
  public  data = input(null, {
    transform: (value) => {
      console.log(value, 'LOG1') // <-- NEVER LOGGED IN TEST
      if (value) {
      
        if (value.instantLoad) {
          this.load();
        }
      }
      return value;
    },
  });
}

TEST

describe('XCollectionComponent', () => {
  let component: XCollectionComponent;
  let fixture: ComponentFixture<XCollectionComponent>;

  const given = async () => {
    await TestBed.configureTestingModule({
      declarations: [XCollectionComponent],
      imports: [
       ...
      ],
      providers: [...],
     ]).compileComponents();

    fixture = TestBed.createComponent(XCollectionComponent);
    component = fixture.componentInstance;

    TestBed.runInInjectionContext(() => {

      fixture.componentRef.setInput('data', {
        ... somedata
      })
    });
    fixture.detectChanges();
 }
it('some test', async() => {
  await given();
  // rest of test
});
}

I also tried use test-practise called "test host strategy" but I also doesn't work.

TEST-COMPONENT:

@Component({
  selector: `test-component`,
  template: ` <x-collection #testing [data]="data"></x-collection>`,
})
class TestComponent {

  data = {
    ... some data
  };
}

I receive error:

NG0303: Can't bind to 'data' since it isn't a known property of 'x-collection' (used in the 'TestComponent' component template).

Does anyone know why this doesn't work? Why is the input signal not recognized in tests?


Solution

  • I fixed it by making update from 17.1.3 to 17.3.5