EmandM / ts-mock-imports

Intuitive mocking library for Typescript class imports
MIT License
109 stars 8 forks source link

Argument of type <string> is not assignable to parameter of type... #40

Closed cahlan closed 1 year ago

cahlan commented 1 year ago

I'm excited about using this library, and I'm suspecting it's some configuration that's causing me headaches. But I have a 3rd party library (airtable) that I am trying to stub for testing purposes. Below is my simplified code:

import { ImportMock } from "ts-mock-imports";
import Airtable from "airtable";

const airtableMock = ImportMock.mockClass(Airtable, "Airtable");
const stub = airtableMock.mock("destroy");

I keep getting the following errors for the mockClass and the mock functions:

error TS2345: Argument of type '"Airtable"' is not assignable to parameter of type '"prototype" | "Base" | "Record" | "Table" | "Error" | "apiKey" | "apiVersion" | "endpointUrl" | "noRetryIfRateLimited" | "requestTimeout" | "default_config" | "configure" | "base" | undefined'.

8 const airtableMock = ImportMock.mockClass(Airtable, "Airtable");
error TS2345: Argument of type '"destroy"' is not assignable to parameter of type '"prototype" | "Base" | "Record" | "Table" | "Error" | "apiKey" | "apiVersion" | "endpointUrl" | "noRetryIfRateLimited" | "requestTimeout" | "default_config" | "configure" | "base" | undefined'.

8 ImportMock.mockFunction(Airtable, "destroy");
cahlan commented 1 year ago

Closing as I realized it was a problem in the way I was trying to mock the class/function. Didn't understand the process well enough. After reading through the docs and source code, I think I'm on the right track.