@@ -2,6 +2,7 @@ import {enableAutoUnmount, flushPromises, mount} from '@vue/test-utils'
2
2
import { afterEach , describe , expect , it , vi } from 'vitest'
3
3
import { nextTick } from 'vue'
4
4
import VBToggle from './BToggle'
5
+ import { asyncTimeout } from '../../tests/utils'
5
6
6
7
// Emitted control event for collapse (emitted to collapse)
7
8
const EVENT_TOGGLE = 'bv-toggle'
@@ -40,6 +41,7 @@ describe('toggle directive', () => {
40
41
expect ( $button . classes ( ) ) . not . toContain ( 'not-collapsed' )
41
42
42
43
await $button . trigger ( 'click' )
44
+ await asyncTimeout ( 50 )
43
45
expect ( spy ) . toHaveBeenCalledTimes ( 1 )
44
46
45
47
// Since there is no target collapse to respond with the
@@ -81,6 +83,7 @@ describe('toggle directive', () => {
81
83
expect ( $button . classes ( ) ) . not . toContain ( 'not-collapsed' )
82
84
83
85
await $button . trigger ( 'click' )
86
+ await asyncTimeout ( 50 )
84
87
expect ( spy ) . toHaveBeenCalledTimes ( 1 )
85
88
86
89
// Since there is no target collapse to respond with the
@@ -121,6 +124,7 @@ describe('toggle directive', () => {
121
124
expect ( $button . classes ( ) ) . not . toContain ( 'not-collapsed' )
122
125
123
126
await $button . trigger ( 'click' )
127
+ await asyncTimeout ( 50 )
124
128
expect ( spy ) . toHaveBeenCalledTimes ( 1 )
125
129
126
130
// Since there is no target collapse to respond with the
@@ -162,6 +166,7 @@ describe('toggle directive', () => {
162
166
expect ( $link . classes ( ) ) . not . toContain ( 'not-collapsed' )
163
167
164
168
await $link . trigger ( 'click' )
169
+ await asyncTimeout ( 50 )
165
170
expect ( spy ) . toHaveBeenCalledTimes ( 1 )
166
171
167
172
// Since there is no target collapse to respond with the
@@ -173,8 +178,7 @@ describe('toggle directive', () => {
173
178
expect ( $link . classes ( ) ) . not . toContain ( 'not-collapsed' )
174
179
} )
175
180
176
- // Does not currently support dynamic updates to target list (bootstrap-vue does)
177
- it . skip ( 'works with multiple targets, and updates when targets change' , async ( ) => {
181
+ it ( 'works with multiple targets, and updates when targets change' , async ( ) => {
178
182
const spy1 = vi . fn ( )
179
183
const spy2 = vi . fn ( )
180
184
const App = {
@@ -188,12 +192,12 @@ describe('toggle directive', () => {
188
192
} ,
189
193
} ,
190
194
mounted ( ) {
191
- document . getElementById ( 'test ' ) ?. addEventListener ( EVENT_TOGGLE , spy1 )
192
- document . getElementById ( 'test ' ) ?. addEventListener ( EVENT_TOGGLE , spy2 )
195
+ document . getElementById ( 'test1 ' ) ?. addEventListener ( EVENT_TOGGLE , spy1 )
196
+ document . getElementById ( 'test2 ' ) ?. addEventListener ( EVENT_TOGGLE , spy2 )
193
197
} ,
194
198
destroy ( ) {
195
- document . getElementById ( 'test ' ) ?. removeEventListener ( EVENT_TOGGLE , spy1 )
196
- document . getElementById ( 'test ' ) ?. removeEventListener ( EVENT_TOGGLE , spy2 )
199
+ document . getElementById ( 'test1 ' ) ?. removeEventListener ( EVENT_TOGGLE , spy1 )
200
+ document . getElementById ( 'test2 ' ) ?. removeEventListener ( EVENT_TOGGLE , spy2 )
197
201
} ,
198
202
template : `<button v-b-toggle="target">button</button><div id="test1"></div><div id="test2"></div>` ,
199
203
}
@@ -227,6 +231,7 @@ describe('toggle directive', () => {
227
231
expect ( spy2 ) . not . toHaveBeenCalled ( )
228
232
229
233
await $button . trigger ( 'click' )
234
+ await asyncTimeout ( 50 )
230
235
expect ( spy1 ) . toHaveBeenCalledTimes ( 1 )
231
236
expect ( spy2 ) . toHaveBeenCalledTimes ( 1 )
232
237
@@ -246,6 +251,7 @@ describe('toggle directive', () => {
246
251
expect ( spy2 ) . toHaveBeenCalledTimes ( 1 )
247
252
248
253
await $button . trigger ( 'click' )
254
+ await asyncTimeout ( 50 )
249
255
expect ( spy1 ) . toHaveBeenCalledTimes ( 1 )
250
256
expect ( spy2 ) . toHaveBeenCalledTimes ( 2 )
251
257
@@ -296,6 +302,7 @@ describe('toggle directive', () => {
296
302
expect ( $span . text ( ) ) . toBe ( 'span' )
297
303
298
304
await $span . trigger ( 'click' )
305
+ await asyncTimeout ( 50 )
299
306
expect ( spy ) . toHaveBeenCalledTimes ( 1 )
300
307
expect ( $span . attributes ( 'role' ) ) . toBe ( 'button' )
301
308
expect ( $span . attributes ( 'tabindex' ) ) . toBe ( '0' )
0 commit comments