useNostr (9), useFightCache (5), useOnlineStatus (4) composable tests. Added fake-indexeddb dev dependency for IDB tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
59 lines
1.4 KiB
TypeScript
59 lines
1.4 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { fightEvents, type FightEvent } from './events.js'
|
|
|
|
describe('fightEvents', () => {
|
|
it('emits events to fight-specific listeners', () => {
|
|
const events: FightEvent[] = []
|
|
const unsub = fightEvents.on('fight-1', (e) => events.push(e))
|
|
|
|
fightEvents.emit({
|
|
fightId: 'fight-1',
|
|
type: 'test',
|
|
data: { msg: 'hello' },
|
|
timestamp: new Date().toISOString(),
|
|
})
|
|
|
|
expect(events).toHaveLength(1)
|
|
expect(events[0].data.msg).toBe('hello')
|
|
unsub()
|
|
})
|
|
|
|
it('cleanup removes all listeners for a fight', () => {
|
|
const events: FightEvent[] = []
|
|
fightEvents.on('fight-cleanup', (e) => events.push(e))
|
|
fightEvents.on('fight-cleanup', (e) => events.push(e))
|
|
|
|
fightEvents.cleanup('fight-cleanup')
|
|
|
|
fightEvents.emit({
|
|
fightId: 'fight-cleanup',
|
|
type: 'test',
|
|
data: {},
|
|
timestamp: new Date().toISOString(),
|
|
})
|
|
|
|
expect(events).toHaveLength(0)
|
|
})
|
|
|
|
it('global listeners receive all events', () => {
|
|
const events: FightEvent[] = []
|
|
const unsub = fightEvents.onAll((e) => events.push(e))
|
|
|
|
fightEvents.emit({
|
|
fightId: 'fight-global-1',
|
|
type: 'test',
|
|
data: {},
|
|
timestamp: new Date().toISOString(),
|
|
})
|
|
fightEvents.emit({
|
|
fightId: 'fight-global-2',
|
|
type: 'test',
|
|
data: {},
|
|
timestamp: new Date().toISOString(),
|
|
})
|
|
|
|
expect(events).toHaveLength(2)
|
|
unsub()
|
|
})
|
|
})
|