Skip to content

feat(checkbox): add required prop #30157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 4, 2025
Prev Previous commit
Next Next commit
test(checkbox): add required prop tests
  • Loading branch information
OS-giulianasilva committed Jan 24, 2025
commit 397c72aadd5559f90af5004c27ed24298582547b
30 changes: 30 additions & 0 deletions core/src/components/checkbox/test/checkbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,33 @@ describe('ion-checkbox: indeterminate', () => {
expect(checkbox.getAttribute('aria-checked')).toBe('mixed');
});
});

describe('ion-checkbox: required', () => {
it('should have a required attribute in inner input when true', async () => {
const page = await newSpecPage({
components: [Checkbox],
html: `
<ion-checkbox required="true">Checkbox</ion-checkbox>
`,
});

const checkbox = page.body.querySelector('ion-checkbox')!;
const nativeInput = checkbox.shadowRoot?.querySelector("input[type=checkbox]")!;

expect(nativeInput.hasAttribute('required')).toBeTruthy();
});

it('should not have a required attribute in inner input when false', async () => {
const page = await newSpecPage({
components: [Checkbox],
html: `
<ion-checkbox required="false">Checkbox</ion-checkbox>
`,
});

const checkbox = page.body.querySelector('ion-checkbox')!;
const nativeInput = checkbox.shadowRoot?.querySelector("input[type=checkbox]")!;

expect(nativeInput.hasAttribute('required')).toBeFalsy();
});
});
Loading