@@ -1764,4 +1764,64 @@ describe('Multiselect.vue', () => {
17641764 expect ( wrapper . emitted ( ) [ 'update:modelValue' ] ) . toEqual ( [ [ '1' ] ] )
17651765 } )
17661766 } )
1767+ describe ( 'required prop' , ( ) => {
1768+ test ( 'should not have required value if required is false' , ( ) => {
1769+ const wrapper = shallowMount ( Multiselect , {
1770+ props : {
1771+ modelValue : [ ] ,
1772+ options : [ '1' , '2' , '3' , '4' , '5' ] ,
1773+ required : false
1774+ }
1775+ } )
1776+ expect ( wrapper . get ( '.multiselect__input' ) . attributes ( 'required' ) ) . toBeUndefined ( )
1777+ } )
1778+ test ( 'should have required attribute if there is no value' , ( ) => {
1779+ const wrapper = shallowMount ( Multiselect , {
1780+ props : {
1781+ modelValue : [ ] ,
1782+ options : [ '1' , '2' , '3' , '4' , '5' ] ,
1783+ required : true
1784+ }
1785+ } )
1786+ expect ( wrapper . get ( '.multiselect__input' ) . attributes ( 'required' ) ) . toEqual ( '' )
1787+ } )
1788+ test ( 'should not required attribute if there is a value' , ( ) => {
1789+ const wrapper = shallowMount ( Multiselect , {
1790+ props : {
1791+ modelValue : [ '1' ] ,
1792+ options : [ '1' , '2' , '3' , '4' , '5' ] ,
1793+ required : true
1794+ }
1795+ } )
1796+ expect ( wrapper . get ( '.multiselect__input' ) . attributes ( 'required' ) ) . toBeUndefined ( )
1797+ } )
1798+ test ( 'should required if a value is removed' , async ( ) => {
1799+ const wrapper = shallowMount ( Multiselect , {
1800+ props : {
1801+ modelValue : [ '1' ] ,
1802+ options : [ '1' , '2' , '3' , '4' , '5' ] ,
1803+ required : true ,
1804+ 'onUpdate:modelValue' : ( e ) => wrapper . setProps ( { modelValue : e } )
1805+ }
1806+ } )
1807+ expect ( wrapper . get ( '.multiselect__input' ) . attributes ( 'required' ) ) . toBeUndefined ( )
1808+ wrapper . vm . removeElement ( wrapper . vm . internalValue [ 0 ] )
1809+ await wrapper . vm . $nextTick ( )
1810+ expect ( wrapper . get ( '.multiselect__input' ) . attributes ( 'required' ) ) . toBe ( '' )
1811+ } )
1812+ test ( 'should not required value if a value is set' , async ( ) => {
1813+ const wrapper = shallowMount ( Multiselect , {
1814+ props : {
1815+ modelValue : [ ] ,
1816+ options : [ '1' , '2' , '3' , '4' , '5' ] ,
1817+ required : true ,
1818+ 'onUpdate:modelValue' : ( e ) => wrapper . setProps ( { modelValue : e } )
1819+ }
1820+ } )
1821+ expect ( wrapper . get ( '.multiselect__input' ) . attributes ( 'required' ) ) . toBe ( '' )
1822+ wrapper . vm . select ( wrapper . vm . options [ 0 ] )
1823+ await wrapper . vm . $nextTick ( )
1824+ expect ( wrapper . get ( '.multiselect__input' ) . attributes ( 'required' ) ) . toBeUndefined ( )
1825+ } )
1826+ } )
17671827} )
0 commit comments