Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mtusnio committed Oct 29, 2024
1 parent cdefa34 commit d598c5f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lib/setup.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import { jest } from '@jest/globals';
import { expect, jest } from '@jest/globals';
import * as setup from "./setup.js";

jest.useFakeTimers();
Expand All @@ -13,6 +13,14 @@ afterEach(async () => {
test("install sets up the context menus properly", async () => {
const createContextMenu = jest.spyOn(chrome.contextMenus, "create").mockReturnValue();
const addListener = jest.spyOn(chrome.contextMenus.onClicked, "addListener").mockReturnValue();
jest.spyOn(chrome.tabs, "query").mockReturnValue([
{
tabId: 1,
url: "https://test.local"
}
]);
const insertCSS = jest.spyOn(chrome.scripting, "insertCSS").mockReturnValue();
const executeScript = jest.spyOn(chrome.scripting, "executeScript").mockReturnValue();

await setup.install()

Expand All @@ -27,6 +35,8 @@ test("install sets up the context menus properly", async () => {
contexts: ["action"]
})
expect(addListener).toHaveBeenCalled()
expect(insertCSS).toHaveBeenCalledTimes(1)
expect(executeScript).toHaveBeenCalledTimes(1)
})

test("activate extension configures the dictionary, changes enabled status and changes the badge", async () => {
Expand Down
7 changes: 6 additions & 1 deletion mock-extension-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ global.chrome = {
addListener: () => { throw Error("Not Implemented"); },
onUpdated: () => { throw Error("Not Implemented"); }
},
sendMessage: () => { throw Error("Not Implemented"); }
sendMessage: () => { throw Error("Not Implemented"); },
query: () => { throw Error("Not Implemented"); }
},

runtime: {
Expand Down Expand Up @@ -57,6 +58,10 @@ global.chrome = {
onClicked: {
addListener: () => { throw Error("Not implemented") }
}
},
scripting: {
insertCSS: () => { throw Error("Not implemented") },
executeScript: () => { throw Error("Not implemented") },
}
};

Expand Down

0 comments on commit d598c5f

Please sign in to comment.