1
- import { describe , expect , it , vi , } from 'vitest'
1
+ import { describe , expect , it , vi } from 'vitest'
2
2
import { ClientEventBus } from '@tanstack/devtools-event-bus/client'
3
3
import { EventClient } from '../src'
4
4
@@ -35,14 +35,16 @@ describe('EventClient', () => {
35
35
it ( 'if the global target is set it should re-use it for emitting/listening/removing of events' , ( ) => {
36
36
const target = new EventTarget ( )
37
37
const handleSuccessConnection = vi . fn ( )
38
- target . addEventListener ( "tanstack-connect" , ( ) => {
39
- target . dispatchEvent (
40
- new CustomEvent ( "tanstack-connect-success" )
41
- )
38
+ target . addEventListener ( 'tanstack-connect' , ( ) => {
39
+ target . dispatchEvent ( new CustomEvent ( 'tanstack-connect-success' ) )
42
40
} )
43
41
globalThis . __TANSTACK_EVENT_TARGET__ = null
44
42
45
- vi . spyOn ( globalThis , '__TANSTACK_EVENT_TARGET__' , 'get' ) . mockImplementation ( ( ) => {
43
+ vi . spyOn (
44
+ globalThis ,
45
+ '__TANSTACK_EVENT_TARGET__' ,
46
+ 'get' ,
47
+ ) . mockImplementation ( ( ) => {
46
48
return target
47
49
} )
48
50
const client = new EventClient ( {
@@ -52,7 +54,7 @@ describe('EventClient', () => {
52
54
const targetEmitSpy = vi . spyOn ( target , 'dispatchEvent' )
53
55
const targetListenSpy = vi . spyOn ( target , 'addEventListener' )
54
56
const targetRemoveSpy = vi . spyOn ( target , 'removeEventListener' )
55
- const cleanup = client . on ( 'test:event' , ( ) => { } )
57
+ const cleanup = client . on ( 'test:event' , ( ) => { } )
56
58
cleanup ( )
57
59
client . emit ( 'test:event' , { foo : 'bar' } )
58
60
expect ( targetEmitSpy ) . toHaveBeenCalledWith ( expect . any ( Event ) )
@@ -65,7 +67,7 @@ describe('EventClient', () => {
65
67
expect . any ( Function ) ,
66
68
)
67
69
vi . resetAllMocks ( )
68
- target . removeEventListener ( " tanstack-connect" , handleSuccessConnection )
70
+ target . removeEventListener ( ' tanstack-connect' , handleSuccessConnection )
69
71
} )
70
72
it ( 'should use the window object if the globalTarget is not set for emitting/listening/removing of events' , ( ) => {
71
73
const target = window
@@ -76,7 +78,7 @@ describe('EventClient', () => {
76
78
const targetEmitSpy = vi . spyOn ( target , 'dispatchEvent' )
77
79
const targetListenSpy = vi . spyOn ( target , 'addEventListener' )
78
80
const targetRemoveSpy = vi . spyOn ( target , 'removeEventListener' )
79
- const cleanup = client . on ( 'test:event' , ( ) => { } )
81
+ const cleanup = client . on ( 'test:event' , ( ) => { } )
80
82
cleanup ( )
81
83
client . emit ( 'test:event' , { foo : 'bar' } )
82
84
expect ( targetEmitSpy ) . toHaveBeenCalledWith ( expect . any ( Event ) )
@@ -89,7 +91,6 @@ describe('EventClient', () => {
89
91
expect . any ( Function ) ,
90
92
)
91
93
} )
92
-
93
94
} )
94
95
95
96
describe ( 'on' , ( ) => {
@@ -100,7 +101,7 @@ describe('EventClient', () => {
100
101
} )
101
102
102
103
const eventBusSpy = vi . spyOn ( clientBusEmitTarget , 'addEventListener' )
103
- client . on ( 'event' , ( ) => { } )
104
+ client . on ( 'event' , ( ) => { } )
104
105
expect ( eventBusSpy ) . toHaveBeenCalledWith (
105
106
'test:event' ,
106
107
expect . any ( Function ) ,
0 commit comments