test(toggle): add required prop tests

This commit is contained in:
giuliana
2025-01-24 12:10:20 +00:00
parent 8ecb96e737
commit 82eb743eab
2 changed files with 32 additions and 0 deletions

View File

@@ -54,3 +54,4 @@ describe('ion-checkbox: indeterminate', () => {
expect(checkbox.getAttribute('aria-checked')).toBe('mixed');
});
});

View File

@@ -2,6 +2,7 @@ import { newSpecPage } from '@stencil/core/testing';
import { config } from '../../../global/config';
import { Toggle } from '../toggle';
import { toggle } from 'ionicons/icons';
describe('toggle', () => {
beforeEach(() => {
@@ -75,3 +76,33 @@ describe('ion-toggle: disabled', () => {
expect(toggle.checked).toBe(false);
});
});
describe('ion-toggle: required', () => {
it('should have a required attribute in inner input when true', async () => {
const page = await newSpecPage({
components: [Toggle],
html: `
<ion-toggle required="true">Toggle</ion-toggle>
`,
});
const toggle = page.body.querySelector('ion-toggle')!;
const nativeInput = toggle.shadowRoot?.querySelector("input[role=switch]")!;
expect(nativeInput.hasAttribute('required')).toBeTruthy();
});
it('should not have a required attribute in inner input when false', async () => {
const page = await newSpecPage({
components: [Toggle],
html: `
<ion-toggle required="false">Toggle</ion-toggle>
`,
});
const toggle = page.body.querySelector('ion-toggle')!;
const nativeInput = toggle.shadowRoot?.querySelector("input[role=switch]")!;
expect(nativeInput.hasAttribute('required')).toBeFalsy();
});
});