There is a past question on this topic, but no answer was posted:
I want to make a type for testdouble-jest
, but the second argument in its exported function is the global jest
instance, which is declared in @types/jest
as a top-level declared namespace:
declare namespace jest {
mock(): something
// ...
}
EDIT: here are the types: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/jest/index.d.ts
How can I refer to this global object in my test-double.d.ts
declaration? My declaration looks as follows, but with partial success:
/// <reference types="jest" />
// do i actually need the above directive?
declare module "testdouble-jest" {
import * as td from "testdouble"; // the testdouble stuff works
export type TestdoubleJest = typeof td & {
mock: typeof jest.mock; // this actually appears to work
};
function setupTestdoubleJest(
testdouble: typeof td,
jest: typeof jest // this just resolves to any
): TestdoubleJest;
export = setupTestdoubleJest;
}
If anyone knows how to do this, I would really appreciate it!
EDIT 2: There are some examples on DefinitelyTyped of people either augmenting the ‘jest‘ namespace or using its members (like I did with jest.mock
), but I can't find one referring to the actual global jest
object.