angular-testing-library
angular-testing-library copied to clipboard
How test mat-checkbox?
I'm trying to test a component that has a mat-checkbox. But every time I simulate the click on the checkbox and make the assert the expected result is not the one returned.
Ex:
const checkboxes = await screen.getAllByTestId('checkbox-benefit');
const checkbox = checkboxes[0];
expect(checkbox).not.toBeChecked()
userEvent.click(checkbox);
component.fixture.detectChanges();
expect(checkbox).toBeChecked() // Failed, mark false
Any example for this?
That should work, see https://github.com/testing-library/angular-testing-library/pull/363
Also, make sure that you select the input control and not the mat-checkbox container.
That should work, see #363
Thanks!!