@@ -216,6 +216,102 @@ describe(`runtime-dom: events patching`, () => {
216216 expect ( fn2 ) . toHaveBeenCalledTimes ( 1 )
217217 } )
218218
219+ // #8334
220+ test ( 'should support once passive capture' , async ( ) => {
221+ const el = document . createElement ( 'div' )
222+
223+ const onOnce = vi . fn ( )
224+ const onPassive = vi . fn ( )
225+ const onCapture = vi . fn ( )
226+
227+ patchProp ( el , 'onOnce' , null , onOnce )
228+ patchProp ( el , 'onPassive' , null , onPassive )
229+ patchProp ( el , 'onCapture' , null , onCapture )
230+
231+ el . dispatchEvent ( new Event ( 'once' ) )
232+ await timeout ( )
233+ expect ( onOnce ) . toHaveBeenCalledTimes ( 1 )
234+
235+ el . dispatchEvent ( new Event ( 'passive' ) )
236+ await timeout ( )
237+ expect ( onPassive ) . toHaveBeenCalledTimes ( 1 )
238+
239+ el . dispatchEvent ( new Event ( 'capture' ) )
240+ await timeout ( )
241+ expect ( onCapture ) . toHaveBeenCalledTimes ( 1 )
242+ } )
243+
244+ test ( 'should support once passive capture in web-components' , async ( ) => {
245+ class TestCustomElement extends HTMLElement {
246+ constructor ( ) {
247+ super ( )
248+ }
249+ }
250+
251+ if ( ! window . customElements . get ( 'hello-world' ) ) {
252+ window . customElements . define ( 'hello-world' , TestCustomElement )
253+ }
254+
255+ const customElement = document . createElement ( 'hello-world' )
256+
257+ const onOnce = vi . fn ( )
258+ const onPassive = vi . fn ( )
259+ const onCapture = vi . fn ( )
260+
261+ patchProp ( customElement , 'onOnce' , null , onOnce )
262+ patchProp ( customElement , 'onPassive' , null , onPassive )
263+ patchProp ( customElement , 'onCapture' , null , onCapture )
264+
265+ customElement . dispatchEvent ( new CustomEvent ( 'once' ) )
266+ expect ( onOnce ) . toHaveBeenCalledTimes ( 1 )
267+
268+ customElement . dispatchEvent ( new CustomEvent ( 'passive' ) )
269+ expect ( onPassive ) . toHaveBeenCalledTimes ( 1 )
270+
271+ customElement . dispatchEvent ( new CustomEvent ( 'capture' ) )
272+ expect ( onCapture ) . toHaveBeenCalledTimes ( 1 )
273+ } )
274+
275+ test ( 'should support once event with the once modifier' , async ( ) => {
276+ const el = document . createElement ( 'div' )
277+
278+ const onOnce = vi . fn ( )
279+
280+ patchProp ( el , 'onOnceOnce' , null , onOnce )
281+
282+ el . dispatchEvent ( new Event ( 'once' ) )
283+ await timeout ( )
284+ expect ( onOnce ) . toHaveBeenCalledTimes ( 1 )
285+
286+ el . dispatchEvent ( new Event ( 'once' ) )
287+ await timeout ( )
288+ expect ( onOnce ) . toHaveBeenCalledTimes ( 1 )
289+ } )
290+
291+ test ( 'should support preserved-case option modifier event names' , async ( ) => {
292+ const el = document . createElement ( 'div' )
293+
294+ const onOnce = vi . fn ( )
295+ const onPassive = vi . fn ( )
296+ const onCapture = vi . fn ( )
297+
298+ patchProp ( el , 'on:Once' , null , onOnce )
299+ patchProp ( el , 'on:Passive' , null , onPassive )
300+ patchProp ( el , 'on:Capture' , null , onCapture )
301+
302+ el . dispatchEvent ( new Event ( 'Once' ) )
303+ await timeout ( )
304+ expect ( onOnce ) . toHaveBeenCalledTimes ( 1 )
305+
306+ el . dispatchEvent ( new Event ( 'Passive' ) )
307+ await timeout ( )
308+ expect ( onPassive ) . toHaveBeenCalledTimes ( 1 )
309+
310+ el . dispatchEvent ( new Event ( 'Capture' ) )
311+ await timeout ( )
312+ expect ( onCapture ) . toHaveBeenCalledTimes ( 1 )
313+ } )
314+
219315 it ( 'handles an unknown type' , ( ) => {
220316 const el = document . createElement ( 'div' )
221317 patchProp ( el , 'onClick' , null , 'test' )
0 commit comments