Lusito / mockzilla-webextension

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

Home Page:https://lusito.github.io/mockzilla-webextension/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Need global mockzillaNode

kartikwatwani opened this issue · comments

I mock browser.tabs.query with different responses in different tests. Due to some reason, I get the response I set in beforeEach even if I change the mock inside a test using mockBrowser.tabs.query.mock. I found that using mockBrowserNode.disableAndVerify followed by a call to mockBrowserNode.enable in arranging part of the test where I change tabs.query response gives me the updated tab. Previously I wasn't using this module and getting references to mockBrowserNode separately in each file using deepMock function but it felt very tedious doing it in every test file so now I switch to this module to get global reference to mockBrowser but I am also in the need of mockBrowserNode in just one test file for now. I tried using deepMock for single file but it is giving error browser.storage.local running after tests have completed. I read in one of the issues on mockZilla github page that the one user said that it was due to global mockBrowser interfering with local mockBrowser object.

I don't think it's good practice to expect/mock something in the before block and then reset it, as it makes grasping the test content harder.

That is my opinion though, so I've exposed mockBrowserRootNode in 0.12.0, so it's up to you.

Thank you for the opinion and the update :)