import register from "./register" import watch from "./watch" import notify from "./notify" jest.mock("./watch") jest.mock("./notify") const mockedNotify = jest.mocked(notify) const mockedWatch = jest.mocked(watch) const recipientSubscriptionJSON = { endpoint: "https://zombo.com", expirationTime: null, keys: { auth: "O_JFRKmhy3OU9LfpfWeQ8Q", p256dh: "somegoofystring", }, } describe("register", () => { beforeEach(() => { mockedWatch.mockImplementation(() => jest.fn()) }) test("starts a watch for the provided event", () => { register({ type: "left to go in class", data: { count: 5, class: 2102, }, recipientSubscriptionJSON, }) const watchCallback = mockedWatch.mock.calls[0][0].callback expect(mockedNotify).toHaveBeenCalledWith(recipientSubscriptionJSON, { title: "5 left to go in class 2102", }) }) })