angular-testing-library icon indicating copy to clipboard operation
angular-testing-library copied to clipboard

How test mat-checkbox?

Open sinkz opened this issue 3 years ago • 3 comments

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?

sinkz avatar Jan 27 '23 00:01 sinkz

That should work, see https://github.com/testing-library/angular-testing-library/pull/363

timdeschryver avatar Jan 27 '23 18:01 timdeschryver

Also, make sure that you select the input control and not the mat-checkbox container.

timdeschryver avatar Jan 28 '23 15:01 timdeschryver

That should work, see #363

Thanks!!

sinkz avatar Jan 30 '23 13:01 sinkz