1
1
import { createSelect , destroy , keyup , keydown , findAll , getValue } from 'unit-test-helpers'
2
2
import { toBeVisible } from '@testing-library/jest-dom/matchers'
3
- import { nextTick } from 'vue'
3
+ import { ref , nextTick , version } from 'vue'
4
+ import Multiselect from './../../src/Multiselect.vue'
5
+ import { mount } from '@vue/test-utils'
4
6
import testSearch from './helpers/testSearch'
5
7
6
8
expect . extend ( { toBeVisible} )
7
9
10
+ const describeVue3Only = ( version . startsWith ( '3' ) ? describe : describe . skip )
11
+
8
12
describe ( 'Multiselect' , ( ) => {
9
13
describe ( 'General' , ( ) => {
10
14
it ( 'should render Multiselect' , ( ) => {
@@ -686,5 +690,31 @@ describe('Multiselect', () => {
686
690
expect ( getValue ( select ) ) . toStrictEqual ( [ 0 , 1 ] )
687
691
} )
688
692
} )
693
+
694
+ describeVue3Only ( 'Composition API' , ( ) => {
695
+ // This test is only possible with Vue 3 because the Composition API is used.
696
+ it ( 'show selected option when added' , async ( ) => {
697
+ const values = ref ( [ 'option1' ] )
698
+ const options = ref ( [ 'option2' ] )
699
+
700
+ const wrapper = mount ( Multiselect , {
701
+ props : {
702
+ mode : 'tags' ,
703
+ value : values ,
704
+ options : options ,
705
+ // this is the default, it is set to highlight the fact
706
+ allowAbsent : false ,
707
+ } ,
708
+ } )
709
+
710
+ options . value = [ 'option1' , 'option2' ]
711
+ values . value = [ 'option1' , 'option2' ]
712
+
713
+ await nextTick ( )
714
+
715
+ const selectedValues = wrapper . findAll ( ".multiselect-tag" ) . map ( tag => tag . text ( ) )
716
+ expect ( selectedValues ) . toEqual ( [ 'option1' , "option2" ] )
717
+ } )
718
+ } )
689
719
} )
690
720
} )
0 commit comments