Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Struggling with ts-jest #175

Open
dhakan opened this issue Mar 9, 2023 · 2 comments
Open

Struggling with ts-jest #175

dhakan opened this issue Mar 9, 2023 · 2 comments

Comments

@dhakan
Copy link

dhakan commented Mar 9, 2023

Hi! This seems to be a fantastic project.

Currently I'm trying to test chrome.storage.local.get and chrome.storage.local.set, but I'm struggling to have my typscript environment, more specifically ts-jest understand that mockClear actually exists as per:

beforeEach(() => {
  chrome.storage.local.get.mockClear(); // Property 'mockClear' does not exist on type ... ...
});

I've managed to setup a similar project called jest-fetch-mock, and if I dig into their source, I can see that they have types such as:

export interface FetchMock
    extends jest.MockInstance<Promise<Response>, [string | Request | undefined, RequestInit | undefined]> {
    (input?: string | Request, init?: RequestInit): Promise<Response>;

    // Response mocking
    mockResponse(fn: MockResponseInitFunction): FetchMock;
    mockResponse(response: string, responseInit?: MockParams): FetchMock;

    ...
}

defined in their project. And I can't seem to find something similar in this project.

Could it be that my project doesn't understand that the implementations has actually created functions such as mockClear? Perhaps this project doesn't support typescript testing? If so, maybe I could declare something for the functions I'm using. I just want to make sure I'm not misunderstanding something that you've documented somewhere.

Thanks in advance!

@dhakan
Copy link
Author

dhakan commented Mar 9, 2023

FYI I moved on by doing the following manipulations of the API:

beforeEach(() => {
  chrome.storage.local.clear();
  chrome.runtime.lastError = undefined;
});

@clarkbw
Copy link
Owner

clarkbw commented Mar 10, 2023

Perhaps this project doesn't support typescript testing? If so, maybe I could declare something for the functions I'm using. I just want to make sure I'm not misunderstanding something that you've documented somewhere.

Yes, right now we don't have types supported. But I'd be happy to take a PR for those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants