From ef5e4acb9057d450fcad46bb019d1b3331da4bb5 Mon Sep 17 00:00:00 2001 From: Frieder Schlesier Date: Sun, 12 Feb 2023 13:55:53 +0100 Subject: [PATCH] wip: first draft for jest test EventManager --- src/api/EventManager.spec.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/api/EventManager.spec.ts diff --git a/src/api/EventManager.spec.ts b/src/api/EventManager.spec.ts new file mode 100644 index 0000000..c6bc35e --- /dev/null +++ b/src/api/EventManager.spec.ts @@ -0,0 +1,16 @@ +import { EventManager } from "./EventManager"; + +// https://stackoverflow.com/questions/51418086/jest-expected-mock-function-to-have-been-called-but-it-was-not-called +describe('Event Manager', () => { + + it('addEvent should call appropriate REST APIs', () => { + // FIXME: extract to beforeEach + const em = new EventManager; + const newEntry = EventManager.eventFromDefault() + newEntry.state.publishYoutube = false + + expect(em.pu).toHaveBeenCalledTimes(1) + expect(client.publish).toHaveBeenCalledTimes(1) + expect(client.publish).toBeCalledWith('button/islow', '{true}', {qos: 1}) + }) +})