32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
|
import { beforeEach, describe, expect, it, jest } from '@jest/globals';
|
||
|
|
||
|
import onClicked from '~background/utils/contextMenus/onClicked';
|
||
|
import onInstalled from '~background/utils/runtime/onInstalled';
|
||
|
import onStartup from '~background/utils/runtime/onStartup';
|
||
|
import onBeforeRequest from '~background/utils/webRequest/onBeforeRequest';
|
||
|
import onErrorOccurred from '~background/utils/webRequest/onErrorOccurred';
|
||
|
|
||
|
describe('background/index.ts', () => {
|
||
|
beforeEach(() => {
|
||
|
jest.clearAllMocks();
|
||
|
});
|
||
|
|
||
|
it('should set up all listeners correctly', async () => {
|
||
|
const filter: chrome.webRequest.RequestFilter = { urls: ['<all_urls>'] };
|
||
|
|
||
|
await import('~background');
|
||
|
|
||
|
expect(chrome.contextMenus.onClicked.addListener).toHaveBeenCalledWith(onClicked);
|
||
|
expect(chrome.runtime.onInstalled.addListener).toHaveBeenCalledWith(onInstalled);
|
||
|
expect(chrome.runtime.onStartup.addListener).toHaveBeenCalledWith(onStartup);
|
||
|
expect(chrome.webRequest.onBeforeRequest.addListener).toHaveBeenCalledWith(
|
||
|
onBeforeRequest,
|
||
|
filter
|
||
|
);
|
||
|
expect(chrome.webRequest.onErrorOccurred.addListener).toHaveBeenCalledWith(
|
||
|
onErrorOccurred,
|
||
|
filter
|
||
|
);
|
||
|
});
|
||
|
});
|