From 0bf79e7db80c6874743b2c95358353438260c902 Mon Sep 17 00:00:00 2001 From: hjonasson Date: Fri, 17 Nov 2023 10:50:55 +1300 Subject: [PATCH] Flesh out tests --- main.test.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 main.test.ts diff --git a/main.test.ts b/main.test.ts new file mode 100644 index 0000000..8dbf8b8 --- /dev/null +++ b/main.test.ts @@ -0,0 +1,43 @@ +import { MockAppBuilder } from "./test_helpers/AppBuilder"; +import MyPlugin from "./main"; +import { PluginManifest } from "obsidian"; + +jest.mock("obsidian"); +(window.setInterval as unknown) = jest.fn(); + +const app = MockAppBuilder.make(); + +describe("MyPlugin", () => { + let plugin: MyPlugin; + beforeEach(async () => { + plugin = new MyPlugin(app.done(), {} as PluginManifest); + }); + + it("Should register two open modal commands", async () => { + const addCommandSpy = jest.spyOn(plugin, "addCommand"); + await plugin.onload(); + expect(addCommandSpy).toHaveBeenCalledWith({ + id: "open-sample-modal-simple", + name: "Open sample modal (simple)", + callback: expect.any(Function), + }); + expect(addCommandSpy).toHaveBeenCalledWith({ + id: "open-sample-modal-complex", + name: "Open sample modal (complex)", + checkCallback: expect.any(Function), + }); + }); + + it("Should register a settings tab", async () => { + const addSettingSpy = jest.spyOn(plugin, "addSettingTab"); + await plugin.onload(); + expect(addSettingSpy).toHaveBeenCalledWith(expect.any(Object)); + }); + + it("Should load data and save as settings", async () => { + const plugin = new MyPlugin(app.done(), {} as PluginManifest); + const loadDataSpy = jest.spyOn(plugin, "loadData"); + await plugin.onload(); + expect(loadDataSpy).toHaveBeenCalled(); + }); +});