Skip to content

Commit 397c72a

Browse files
test(checkbox): add required prop tests
1 parent b423ae7 commit 397c72a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

core/src/components/checkbox/test/checkbox.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,33 @@ describe('ion-checkbox: indeterminate', () => {
5454
expect(checkbox.getAttribute('aria-checked')).toBe('mixed');
5555
});
5656
});
57+
58+
describe('ion-checkbox: required', () => {
59+
it('should have a required attribute in inner input when true', async () => {
60+
const page = await newSpecPage({
61+
components: [Checkbox],
62+
html: `
63+
<ion-checkbox required="true">Checkbox</ion-checkbox>
64+
`,
65+
});
66+
67+
const checkbox = page.body.querySelector('ion-checkbox')!;
68+
const nativeInput = checkbox.shadowRoot?.querySelector("input[type=checkbox]")!;
69+
70+
expect(nativeInput.hasAttribute('required')).toBeTruthy();
71+
});
72+
73+
it('should not have a required attribute in inner input when false', async () => {
74+
const page = await newSpecPage({
75+
components: [Checkbox],
76+
html: `
77+
<ion-checkbox required="false">Checkbox</ion-checkbox>
78+
`,
79+
});
80+
81+
const checkbox = page.body.querySelector('ion-checkbox')!;
82+
const nativeInput = checkbox.shadowRoot?.querySelector("input[type=checkbox]")!;
83+
84+
expect(nativeInput.hasAttribute('required')).toBeFalsy();
85+
});
86+
});

0 commit comments

Comments
 (0)