Skip to content

Commit 82eb743

Browse files
test(toggle): add required prop tests
1 parent 8ecb96e commit 82eb743

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,4 @@ describe('ion-checkbox: indeterminate', () => {
5454
expect(checkbox.getAttribute('aria-checked')).toBe('mixed');
5555
});
5656
});
57+

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { newSpecPage } from '@stencil/core/testing';
22

33
import { config } from '../../../global/config';
44
import { Toggle } from '../toggle';
5+
import { toggle } from 'ionicons/icons';
56

67
describe('toggle', () => {
78
beforeEach(() => {
@@ -75,3 +76,33 @@ describe('ion-toggle: disabled', () => {
7576
expect(toggle.checked).toBe(false);
7677
});
7778
});
79+
80+
describe('ion-toggle: required', () => {
81+
it('should have a required attribute in inner input when true', async () => {
82+
const page = await newSpecPage({
83+
components: [Toggle],
84+
html: `
85+
<ion-toggle required="true">Toggle</ion-toggle>
86+
`,
87+
});
88+
89+
const toggle = page.body.querySelector('ion-toggle')!;
90+
const nativeInput = toggle.shadowRoot?.querySelector("input[role=switch]")!;
91+
92+
expect(nativeInput.hasAttribute('required')).toBeTruthy();
93+
});
94+
95+
it('should not have a required attribute in inner input when false', async () => {
96+
const page = await newSpecPage({
97+
components: [Toggle],
98+
html: `
99+
<ion-toggle required="false">Toggle</ion-toggle>
100+
`,
101+
});
102+
103+
const toggle = page.body.querySelector('ion-toggle')!;
104+
const nativeInput = toggle.shadowRoot?.querySelector("input[role=switch]")!;
105+
106+
expect(nativeInput.hasAttribute('required')).toBeFalsy();
107+
});
108+
});

0 commit comments

Comments
 (0)