Skip to content

Commit

Permalink
Merge pull request #499 from asdftd/main
Browse files Browse the repository at this point in the history
Improve replace typings
  • Loading branch information
searls committed Nov 13, 2022
2 parents de7afa0 + 07fdfbc commit fcfb3f3
Showing 1 changed file with 12 additions and 10 deletions.
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

0 comments on commit fcfb3f3

Please sign in to comment.