Skip to content Skip to sidebar Skip to footer

Angular Material 2 - Trigger Change Event In Md-checkbox In A Unit Test

I am having problems triggering a 'change' event for a md-checkbox in an Angular Unit Test, using the test framework setup provided by the Angular CLI. I have a simple component: t

Solution 1:

The handle is not in the md-checkbox but in its label element

de = fixture.debugElement.query(By.css('md-checkbox label'));
el = de.nativeElement;
el.click();

should do the trick

You can also import only MdCheckboxModule instead of MaterialModule.

Post a Comment for "Angular Material 2 - Trigger Change Event In Md-checkbox In A Unit Test"