mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2024-11-17 02:48:31 -07:00
24 lines
484 B
JavaScript
24 lines
484 B
JavaScript
|
const events = {};
|
||
|
|
||
|
const mock = {
|
||
|
publish: jest.fn().mockImplementation((topic, payload, options, cb) => cb()),
|
||
|
end: jest.fn(),
|
||
|
subscribe: jest.fn(),
|
||
|
on: (type, handler) => {
|
||
|
if (type === 'connect') {
|
||
|
handler();
|
||
|
}
|
||
|
|
||
|
events[type] = handler
|
||
|
},
|
||
|
};
|
||
|
|
||
|
const mockConnect = jest.fn().mockReturnValue(mock);
|
||
|
|
||
|
jest.mock('mqtt', () => {
|
||
|
return {connect: mockConnect};
|
||
|
});
|
||
|
|
||
|
module.exports = {
|
||
|
events, ...mock, connect: mockConnect,
|
||
|
};
|