Flesh out tests

This commit is contained in:
hjonasson 2023-11-17 10:50:55 +13:00
parent e1590a004d
commit 0bf79e7db8
No known key found for this signature in database
GPG Key ID: 68D22124ADDEEB04
1 changed files with 43 additions and 0 deletions

43
main.test.ts Normal file
View File

@ -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();
});
});