UNPKG

mockzilla-webextension

Version:

A mocking toolkit for web-extensions leveraging the power of TypeScript to enhance your jest experience.

21 lines (20 loc) 1.09 kB
/// <reference types="jest" /> import { Events } from "webextension-polyfill"; import { MockzillaDeep } from "mockzilla"; export declare class MockzillaEvent<T extends (...args: any[]) => any> { private listeners; private disabled; private prefix; constructor(prefix: string); addListener: jest.Mock<void, [callback: T]>; removeListener: jest.Mock<void, [callback: T]>; hasListener: jest.Mock<boolean, [callback: T]>; hasListeners: jest.Mock<boolean, []>; disable(): void; emit(...args: Parameters<T>): void; private disabledCheck; } export declare type MockzillaEventParameters<T> = T extends (...args: any[]) => any ? Parameters<T> : any[]; export declare type MockzillaEventFunction<T> = T extends Events.Event<infer TFun> ? (...args: MockzillaEventParameters<TFun>) => void : (...args: any[]) => void; export declare type MockzillaEventOf<T> = T extends MockzillaDeep<infer TD> ? MockzillaEvent<MockzillaEventFunction<TD>> : unknown; export declare function mockEvent<T>(builder: MockzillaDeep<T>): MockzillaEvent<MockzillaEventFunction<T>>;