diff --git a/test/extensions/onEvent.test.ts b/test/extensions/onEvent.test.ts index c33a863b..4e7d8e70 100644 --- a/test/extensions/onEvent.test.ts +++ b/test/extensions/onEvent.test.ts @@ -4,24 +4,23 @@ import {mockMQTTPublishAsync} from '../mocks/mqtt'; import {flushPromises} from '../mocks/utils'; import {devices, events as mockZHEvents} from '../mocks/zigbeeHerdsman'; +import {MockInstance} from 'vitest'; + import * as zhc from 'zigbee-herdsman-converters'; import {Controller} from '../../lib/controller'; import * as settings from '../../lib/util/settings'; -const mockOnEvent = vi.fn(); -const mockLivoloOnEvent = vi.fn(); -// @ts-expect-error mock -zhc.onEvent = mockOnEvent; - -const mocksClear = [mockMQTTPublishAsync, mockLogger.warning, mockLogger.debug]; +const mockOnEvent = vi.spyOn(zhc, 'onEvent'); +const mocksClear = [mockMQTTPublishAsync, mockLogger.warning, mockLogger.debug, mockOnEvent]; describe('Extension: OnEvent', () => { let controller: Controller; + let mockLivoloOnEvent: MockInstance; beforeAll(async () => { const mappedLivolo = (await zhc.findByDevice(devices.LIVOLO))!; - mappedLivolo.onEvent = mockLivoloOnEvent; + mockLivoloOnEvent = vi.spyOn(mappedLivolo, 'onEvent'); }); beforeEach(async () => { @@ -39,7 +38,6 @@ describe('Extension: OnEvent', () => { data.writeDefaultConfiguration(); settings.reRead(); mocksClear.forEach((m) => m.mockClear()); - mockOnEvent.mockClear(); }); afterAll(async () => { diff --git a/test/extensions/publish.test.ts b/test/extensions/publish.test.ts index 38788270..668f08a2 100644 --- a/test/extensions/publish.test.ts +++ b/test/extensions/publish.test.ts @@ -7,7 +7,7 @@ import {devices, groups, events as mockZHEvents} from '../mocks/zigbeeHerdsman'; import stringify from 'json-stable-stringify-without-jsonify'; -import * as zhcGlobalStore from 'zigbee-herdsman-converters/lib/store'; +import {clearGlobalStore} from 'zigbee-herdsman-converters'; import {Controller} from '../../lib/controller'; import {loadTopicGetSetRegex} from '../../lib/extension/publish'; @@ -58,7 +58,7 @@ describe('Extension: Publish', () => { g.command.mockClear(); }); - zhcGlobalStore.clear(); + clearGlobalStore(); }); afterAll(async () => { @@ -1511,7 +1511,7 @@ describe('Extension: Publish', () => { await mockMQTTEvents.message('zigbee2mqtt/bulb_color/set', stringify({state: 'ON', brightness: 20, transition: 0.0})); await flushPromises(); - zhcGlobalStore.clear(); + clearGlobalStore(); await mockMQTTEvents.message('zigbee2mqtt/bulb_color/set', stringify({state: 'ON', transition: 1.0})); await flushPromises();