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

Improve replace typings #499

Merged
merged 1 commit into from Nov 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 12 additions & 10 deletions index.d.ts
Expand Up @@ -276,21 +276,24 @@ export function callback(...args: any[]): void;
* that dependency module and ensure your subject is handed a fake instead.
*
* @export
* @param {string} path
* @param {*} [f]
* @param {string} module
* @param {*} [f] replacement
* @returns {*}
*/
export function replace(path: string, f?: any): any;
export function replace<F>(path: string, f?: F): F;
export function replace(path: string): TestDouble<any>;
/**
* Swap out real dependencies with fake one. Intercept calls to `require`
* that dependency module and ensure your subject is handed a fake instead.
*
* @export
* @param {string} path
* @param {string} obj
* @param {*} [f]
* @returns {*}
*/
export function replaceCjs(path: string, f?: any): any;

export function replace<T, K extends keyof T>(obj: T, property: K): TestDouble<T[K]>;
export function replace(obj: {}, property: string): TestDouble<any>;
/**
* Swap out real dependencies with fake one. Intercept calls to `import`
* that dependency module and ensure your subject is handed a fake instead.
Expand All @@ -301,21 +304,20 @@ export function replaceCjs(path: string, f?: any): any;
* @param {*} [defaultExportStub]
* @returns {Promise<{default?: any, [namedExport: string]: any}>}
*/
export function replaceEsm(path: string, namedExportStubs?: any, defaultExportStub?: any):
Promise<{default?: any, [namedExport: string]: any}>;
export function replaceEsm(path: string, namedExportStubs?: any, defaultExportStub?: any): Promise<void>;
export function replaceEsm(path: string): Promise<{default?: any, [namedExport: string]: any}>;

/**
* Swap out real dependencies with fake one. Reference to the property will
* be replace it during your test.
*
* @export
* @param {{}} path
* @param {{}} obj
* @param {string} property
* @param {*} [f]
* @returns {*}
*/
export function replace(path: {}, property: string, f?: any): any;

export function replace<F>(obj: {}, property: string, replacement: F): F;
/**
* Stub a specific function call.
*
Expand Down