Skip to content

Commit 7e2d9ae

Browse files
committed
feat(tests): implement TestClientEventBus for event handling in tests
1 parent 9cc6c8d commit 7e2d9ae

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

packages/devtools-seo/src/json-ld-preview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { For, Show } from 'solid-js'
22
import { Section, SectionDescription } from '@tanstack/devtools-ui'
33
import { isInsideDevtools } from './devtools-dom-filter'
4+
import { sectionHealthScore } from './seo-section-summary'
45
import { useSeoStyles } from './use-seo-styles'
56
import { pickSeverityClass, seoHealthTier } from './seo-severity'
67
import type { SeoSeverity } from './seo-severity'
7-
import { sectionHealthScore } from './seo-section-summary'
88
import type { SeoSectionSummary } from './seo-section-summary'
99

1010
type JsonLdValue = Record<string, unknown>

packages/event-bus-client/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,5 @@
5656
"test:types": "tsc",
5757
"test:build": "publint --strict",
5858
"build": "vite build"
59-
},
60-
"devDependencies": {
61-
"@tanstack/devtools-event-bus": "workspace:*"
6259
}
6360
}

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,41 @@
11
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2-
import { ClientEventBus } from '@tanstack/devtools-event-bus/client'
32
import { EventClient } from '../src'
43

4+
class TestClientEventBus {
5+
#dispatcher = (e: Event) => {
6+
const event = (e as CustomEvent).detail
7+
window.dispatchEvent(new CustomEvent(event.type, { detail: event }))
8+
window.dispatchEvent(
9+
new CustomEvent('tanstack-devtools-global', {
10+
detail: event,
11+
}),
12+
)
13+
}
14+
15+
#connectFunction = () => {
16+
window.dispatchEvent(new CustomEvent('tanstack-connect-success'))
17+
}
18+
19+
start() {
20+
window.addEventListener('tanstack-dispatch-event', this.#dispatcher)
21+
window.addEventListener('tanstack-connect', this.#connectFunction)
22+
}
23+
24+
stop() {
25+
window.removeEventListener('tanstack-dispatch-event', this.#dispatcher)
26+
window.removeEventListener('tanstack-connect', this.#connectFunction)
27+
}
28+
}
29+
530
// client bus uses window to dispatch events
631
const clientBusEmitTarget = window
732

833
describe('EventClient', () => {
9-
let bus: ClientEventBus
34+
let bus: TestClientEventBus
1035

1136
beforeEach(() => {
1237
// Create a fresh bus for each test to ensure isolation
13-
bus = new ClientEventBus()
38+
bus = new TestClientEventBus()
1439
bus.start()
1540
})
1641

0 commit comments

Comments
 (0)