Skip to content

Commit

Permalink
test(checkbox): add required prop tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OS-giulianasilva committed Jan 24, 2025
1 parent b423ae7 commit 397c72a
Showing 1 changed file with 30 additions and 0 deletions.
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();
});
});

0 comments on commit 397c72a

Please sign in to comment.