File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -54,3 +54,4 @@ describe('ion-checkbox: indeterminate', () => {
5454 expect ( checkbox . getAttribute ( 'aria-checked' ) ) . toBe ( 'mixed' ) ;
5555 } ) ;
5656} ) ;
57+
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { newSpecPage } from '@stencil/core/testing';
22
33import { config } from '../../../global/config' ;
44import { Toggle } from '../toggle' ;
5+ import { toggle } from 'ionicons/icons' ;
56
67describe ( '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+ } ) ;
You can’t perform that action at this time.
0 commit comments