jest-chrome icon indicating copy to clipboard operation
jest-chrome copied to clipboard

Type definitions not working with chrome.tabs.query

Open vquigley opened this issue 3 years ago • 2 comments

TS linter is throwing an error when trying to mock chrome.tabs.query

image

I think this is happening because chrome is overloading the query function name in their type definition:

image

But the jest definition only has one definition for the mocked function:

image

vquigley avatar Feb 03 '22 16:02 vquigley

+1 when using chrome.tabs.get in a test

adlerfaulkner avatar Feb 14 '22 06:02 adlerfaulkner

For anyone with this problem, you can trick typescript by casting the api method to jest.Mock like this:

(chrome.tabs.get as jest.Mock).mockImplementation( ... )

adlerfaulkner avatar Mar 08 '22 03:03 adlerfaulkner