Skip to content

Commit ad32fec

Browse files
authored
fix(ignore): Fix tests failing when zhc is linked via pnpm link (#26630)
1 parent c603f42 commit ad32fec

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

test/extensions/onEvent.test.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,23 @@ import {mockMQTTPublishAsync} from '../mocks/mqtt';
44
import {flushPromises} from '../mocks/utils';
55
import {devices, events as mockZHEvents} from '../mocks/zigbeeHerdsman';
66

7+
import {MockInstance} from 'vitest';
8+
79
import * as zhc from 'zigbee-herdsman-converters';
810

911
import {Controller} from '../../lib/controller';
1012
import * as settings from '../../lib/util/settings';
1113

12-
const mockOnEvent = vi.fn();
13-
const mockLivoloOnEvent = vi.fn();
14-
// @ts-expect-error mock
15-
zhc.onEvent = mockOnEvent;
16-
17-
const mocksClear = [mockMQTTPublishAsync, mockLogger.warning, mockLogger.debug];
14+
const mockOnEvent = vi.spyOn(zhc, 'onEvent');
15+
const mocksClear = [mockMQTTPublishAsync, mockLogger.warning, mockLogger.debug, mockOnEvent];
1816

1917
describe('Extension: OnEvent', () => {
2018
let controller: Controller;
19+
let mockLivoloOnEvent: MockInstance;
2120

2221
beforeAll(async () => {
2322
const mappedLivolo = (await zhc.findByDevice(devices.LIVOLO))!;
24-
mappedLivolo.onEvent = mockLivoloOnEvent;
23+
mockLivoloOnEvent = vi.spyOn(mappedLivolo, 'onEvent');
2524
});
2625

2726
beforeEach(async () => {
@@ -39,7 +38,6 @@ describe('Extension: OnEvent', () => {
3938
data.writeDefaultConfiguration();
4039
settings.reRead();
4140
mocksClear.forEach((m) => m.mockClear());
42-
mockOnEvent.mockClear();
4341
});
4442

4543
afterAll(async () => {

test/extensions/publish.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {devices, groups, events as mockZHEvents} from '../mocks/zigbeeHerdsman';
77

88
import stringify from 'json-stable-stringify-without-jsonify';
99

10-
import * as zhcGlobalStore from 'zigbee-herdsman-converters/lib/store';
10+
import {clearGlobalStore} from 'zigbee-herdsman-converters';
1111

1212
import {Controller} from '../../lib/controller';
1313
import {loadTopicGetSetRegex} from '../../lib/extension/publish';
@@ -58,7 +58,7 @@ describe('Extension: Publish', () => {
5858
g.command.mockClear();
5959
});
6060

61-
zhcGlobalStore.clear();
61+
clearGlobalStore();
6262
});
6363

6464
afterAll(async () => {
@@ -1511,7 +1511,7 @@ describe('Extension: Publish', () => {
15111511
await mockMQTTEvents.message('zigbee2mqtt/bulb_color/set', stringify({state: 'ON', brightness: 20, transition: 0.0}));
15121512
await flushPromises();
15131513

1514-
zhcGlobalStore.clear();
1514+
clearGlobalStore();
15151515

15161516
await mockMQTTEvents.message('zigbee2mqtt/bulb_color/set', stringify({state: 'ON', transition: 1.0}));
15171517
await flushPromises();

0 commit comments

Comments
 (0)