Skip to content

Commit fc85922

Browse files
committed
fix: test
1 parent 1820f08 commit fc85922

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

packages/event-bus-client/tests/index.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { describe, expect, it, vi } from 'vitest'
22
import { ClientEventBus } from '@tanstack/devtools-event-bus/client'
33
import { EventClient } from '../src'
44

5-
vi.spyOn(BroadcastChannel.prototype, 'postMessage').mockImplementation(() => {})
5+
vi.stubGlobal('BroadcastChannel', class {
6+
postMessage = vi.fn()
7+
addEventListener = vi.fn()
8+
removeEventListener = vi.fn()
9+
close = vi.fn()
10+
})
611
// start the client bus for testing
712
const bus = new ClientEventBus()
813
bus.start()
@@ -56,7 +61,7 @@ describe('EventClient', () => {
5661
const targetEmitSpy = vi.spyOn(target, 'dispatchEvent')
5762
const targetListenSpy = vi.spyOn(target, 'addEventListener')
5863
const targetRemoveSpy = vi.spyOn(target, 'removeEventListener')
59-
const cleanup = client.on('test:event', () => {})
64+
const cleanup = client.on('test:event', () => { })
6065
cleanup()
6166
client.emit('test:event', { foo: 'bar' })
6267
expect(targetEmitSpy).toHaveBeenCalledWith(expect.any(Event))
@@ -80,7 +85,7 @@ describe('EventClient', () => {
8085
const targetEmitSpy = vi.spyOn(target, 'dispatchEvent')
8186
const targetListenSpy = vi.spyOn(target, 'addEventListener')
8287
const targetRemoveSpy = vi.spyOn(target, 'removeEventListener')
83-
const cleanup = client.on('test:event', () => {})
88+
const cleanup = client.on('test:event', () => { })
8489
cleanup()
8590
client.emit('test:event', { foo: 'bar' })
8691
expect(targetEmitSpy).toHaveBeenCalledWith(expect.any(Event))
@@ -103,7 +108,7 @@ describe('EventClient', () => {
103108
})
104109

105110
const eventBusSpy = vi.spyOn(clientBusEmitTarget, 'addEventListener')
106-
client.on('event', () => {})
111+
client.on('event', () => { })
107112
expect(eventBusSpy).toHaveBeenCalledWith(
108113
'test:event',
109114
expect.any(Function),

packages/event-bus/tests/index.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import { afterEach, describe, expect, it, vi } from 'vitest'
22
import { ClientEventBus } from '../src/client'
33

4-
vi.spyOn(BroadcastChannel.prototype, 'postMessage').mockImplementation(() => {})
4+
vi.stubGlobal('BroadcastChannel', class {
5+
postMessage = vi.fn()
6+
addEventListener = vi.fn()
7+
removeEventListener = vi.fn()
8+
close = vi.fn()
9+
})
510
describe('ClientEventBus', () => {
611
describe('debug', () => {
712
afterEach(() => {
813
vi.restoreAllMocks()
914
})
1015
it('should log events to the console when debug set to true', () => {
11-
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
16+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => { })
1217
const clientBus = new ClientEventBus({ debug: true })
1318
clientBus.start()
1419

@@ -21,7 +26,7 @@ describe('ClientEventBus', () => {
2126
})
2227

2328
it('should not log events to the console when debug set to false', () => {
24-
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
29+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => { })
2530
const clientBus = new ClientEventBus({ debug: false })
2631
clientBus.start()
2732

0 commit comments

Comments
 (0)