Lusito / mockzilla

A mocking toolkit leveraging the power of TypeScript to enhance your jest experience.
https://lusito.github.io/mockzilla/
zlib License
14 stars 2 forks source link

browser.runtime is not implemented #9

Closed kartikwatwani closed 3 years ago

kartikwatwani commented 3 years ago

I am using browser.runtime in my code then in the test file I am using mockzilla as follows:

 */
 import type { Browser } from "webextension-polyfill-ts";
 import { deepMock } from "mockzilla";
 const [browser, mockBrowser, mockBrowserNode] = deepMock<Browser>("browser",false);
 jest.mock("webextension-polyfill-ts", () => ({ browser }));

But when I am running tests I am getting the following error:

Test suite failed to run

    Mock "browser.runtime" is not implemented

    Invocation: 

What should I do to run my tests if I use browser.runtime. If I wish to implement browser.runtime myself can you guide me on it?

Update: I also tried browser.tabs but that is also not working.

Lusito commented 3 years ago

Before every use of a browser property during tests, you'll need to mock it (for example using the expect syntax). See https://lusito.github.io/mockzilla-webextension/browser.html#solution

kartikwatwani commented 3 years ago

I learned how to use this module. Thanks for this!