Stop Zigbee2MQTT with error when initial MQTT connect fails. https://github.com/Koenkk/zigbee2mqtt/issues/8956

This commit is contained in:
Koen Kanters
2021-10-04 22:08:06 +02:00
parent 7415e8416d
commit 23b87755cf
4 changed files with 36 additions and 10 deletions
+12
View File
@@ -25,6 +25,7 @@ describe('Controller', () => {
});
beforeEach(() => {
MQTT.restoreOnMock();
zigbeeHerdsman.returnDevices.splice(0);
mockExit = jest.fn();
controller = new Controller(jest.fn(), mockExit);
@@ -209,6 +210,17 @@ describe('Controller', () => {
expect(mockExit).toHaveBeenCalledTimes(1);
});
it('Start controller fails due to MQTT', async () => {
MQTT.on.mockImplementation((type, handler) => {
if (type === 'error') handler({message: 'addr not found'});
});
await controller.start();
await flushPromises();
expect(logger.error).toHaveBeenCalledWith('MQTT failed to connect: addr not found');
expect(mockExit).toHaveBeenCalledTimes(1);
expect(mockExit).toHaveBeenCalledWith(1);
});
it('Start controller with permit join true', async () => {
settings.set(['permit_join'], false);
await controller.start();