Comparing version 0.0.10 to 0.0.11
@@ -1,4 +0,5 @@ | ||
export interface StrictMock<A extends any[], T> { | ||
declare type Awaited<T> = T extends PromiseLike<infer PT> ? PT : never; | ||
export interface StrictMock<ARGS extends any[], RETURN> { | ||
/** Calls the mock function */ | ||
(...args: A): T; | ||
(...args: ARGS): RETURN; | ||
isExhausted(): boolean; | ||
@@ -9,3 +10,3 @@ /** | ||
*/ | ||
expectedCall<B extends A>(...args: B): { | ||
expectedCall(...args: ARGS): { | ||
/** | ||
@@ -15,15 +16,27 @@ * Sets the return value of calls to the Mock. | ||
*/ | ||
returns<U>(value: U): StrictMock<A, T | U>; | ||
returns(value: RETURN): StrictMock<ARGS, RETURN>; | ||
/** | ||
* Sets the return value wrapped in Promise.resolve of calls to the Mock. | ||
* @param value value to be returned. | ||
*/ | ||
resolvesTo(value: Awaited<RETURN>): StrictMock<ARGS, RETURN>; | ||
/** | ||
* Sets the error thrown by calls to the Mock. | ||
* @param error error to be thrown. | ||
*/ | ||
throws(error: any): StrictMock<A, T>; | ||
throws(error: any): StrictMock<ARGS, RETURN>; | ||
/** | ||
* Sets the error rejected by calls to the Mock. | ||
* @param error error to be thrown. | ||
*/ | ||
rejectsWith(error: any): StrictMock<ARGS, RETURN>; | ||
/** | ||
* Sets the underlying implementation of the Mock. | ||
* @param implementation function to execute. | ||
*/ | ||
executes<U>(implementation: (...args: B) => U): StrictMock<A, T | U>; | ||
executes(implementation: (...args: ARGS) => RETURN): StrictMock<ARGS, RETURN>; | ||
}; | ||
} | ||
export declare function strictMockFn<FN extends (...args: any) => any>(): StrictMock<Parameters<FN>, ReturnType<FN>>; | ||
export declare function strictMockFn<ARGS extends any[], RETURN>(): StrictMock<ARGS, RETURN>; | ||
export {}; |
@@ -39,2 +39,6 @@ "use strict"; | ||
}, | ||
resolvesTo(value) { | ||
queue.push({ args, type: 'return', value: Promise.resolve(value) }); | ||
return mock; | ||
}, | ||
throws(error) { | ||
@@ -44,2 +48,7 @@ queue.push({ args, type: 'throw', error }); | ||
}, | ||
rejectsWith(error) { | ||
// @todo this results in an ugly warning about unhandled rejected promise... | ||
queue.push({ args, type: 'return', value: Promise.reject(error) }); | ||
return mock; | ||
}, | ||
executes(implementation) { | ||
@@ -46,0 +55,0 @@ queue.push({ args, type: 'exec', implementation }); |
@@ -15,3 +15,3 @@ { | ||
"license": "MIT", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"main": "./dist/index.js", | ||
@@ -18,0 +18,0 @@ "types": "./dist/index.d.ts", |
65075
1535