I have a component with a required model. How do I unit test that the value has been updated?
import { Component, model } from '@angular/core';
@Component({
template: `<input type="checkbox" [(ngModel)]="myModel">`
standalone: true,
})
export class BooleanToggler {
readonly myModel = model.required<boolean>();
}
I can set the value of the model with fixture.componentRef.setInput('myModel', true)
. I can toggle the checkbox with (fixture.nativeElement as HTMLElement).querySelector('input')!.click()
. However, this does not trigger an update to myModel, and I cannot spy on the emitter with spyOn(fixture.componentInstance.myModel, 'emit')
, as I would with an @Output()
, as emit
does not exist on ModelSignal
. spyOn(fixture.componentInstance.myModel, 'set')
also does not work.
1