UNPKG

matterbridge-roborock-vacuum-plugin

Version:
28 lines 1.19 kB
import { describe, expect, it, vi } from 'vitest'; import { BehaviorDeviceGeneric } from '../../behaviors/BehaviorDeviceGeneric.js'; import { createMockLogger } from '../helpers/testUtils.js'; describe('BehaviorDeviceGeneric', () => { it('registers and executes a command handler', async () => { const log = createMockLogger(); const b = new BehaviorDeviceGeneric(log); const handler = vi.fn(async (x) => x + 1); b.setCommandHandler('inc', handler); await b.executeCommand('inc', 2); expect(handler).toHaveBeenCalledWith(2); }); it('throws when registering duplicate handler', () => { const log = createMockLogger(); const b = new BehaviorDeviceGeneric(log); const h = vi.fn(); b.setCommandHandler('cmd', h); expect(() => { b.setCommandHandler('cmd', h); }).toThrow(); }); it('throws when executing unregistered command', async () => { const log = createMockLogger(); const b = new BehaviorDeviceGeneric(log); await expect(b.executeCommand('nope')).rejects.toThrow(); }); }); //# sourceMappingURL=BehaviorDeviceGeneric.test.js.map