Cypress component test with ControlValueAccessor fails to find value accessor

46 Views Asked by At

I'm trying to write a component test for my component that implements ControlValueAccessor. The component itself works without issue, but when I try and test it via cypress, I'm getting the "No value accessor for form control unspecified name attribute" error.

This is how I'm trying to mount the component:

const collateralFixture: CollateralByAreaArray[] = [
    {
        'areaName': v4(),
        'collateral': [
            Collateral.forTesting(),
            Collateral.forTesting()
        ]
    },
    {
        'areaName': v4(),
        'collateral': [
            Collateral.forTesting(),
            Collateral.forTesting()
        ]
    }
]

cy
    .mount('<app-collateral-expansion-panel [formControl]="control" />', {
        componentProperties: {
            control: new FormControl<CollateralByAreaArray[]>(collateralFixture)
        },
        imports: [ ReactiveFormsModule, IgxExpansionPanelModule ]
    })

Since I properly provide the NG_VALUE_ACCESSOR in the component, why do I get this error while trying to test?

I'm using version 13.6.6 of cypress and 17.2.4 of Angular.

Collateral is just a class object, that has children, and the forTesting() method just creates random values for the object.

0

There are 0 best solutions below