Skip to content

Commit

Permalink
Add unit tests for main
Browse files Browse the repository at this point in the history
Adds a unit test for the restart event.
  • Loading branch information
llewelld committed May 9, 2022
1 parent 1eb5414 commit 20d4fca
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/lib/__mocks__/mainEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
let handlers = new Map();

const mainEvent = {
on(event, handler) {
handlers.set(event, handler);
},
emit(event) {
handlers.get(event)();
}
};

module.exports = mainEvent;
20 changes: 20 additions & 0 deletions src/main.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,27 @@ process.argv = [null, null, "-vv"];
const { ipcMain } = require("electron");
jest.mock("electron");
process.argv = [];
const mainEvent = require("./lib/mainEvent.js");
jest.mock("./lib/mainEvent.js");
const { main } = require("./main.js");
const window = require("./lib/window.js");
jest.mock("./lib/window.js");
const core = require("./core/core.js");
jest.mock("./core/core.js");

it("should be a singleton", () => {
expect(require("./main.js")).toBeDefined();
});

describe("main", () => {
describe("restart", () => {
it("should restart the app", () => {
mainEvent.emit("restart");
expect(window.send).toHaveBeenCalledWith("user:restart");
expect(window.send).toHaveBeenCalledTimes(1);
expect(core.reset).toHaveBeenCalledTimes(1);
expect(core.prepare).toHaveBeenCalledTimes(1);
expect(core.prepare).toHaveBeenCalledWith(undefined, true);
});
});
});

0 comments on commit 20d4fca

Please sign in to comment.