mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Make typing of higher order function for error suppression not lie
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
6411b225c0
commit
bafa7377f6
@ -58,8 +58,8 @@ describe("with-error-suppression", () => {
|
||||
});
|
||||
|
||||
describe("given decorated async function", () => {
|
||||
let decorated: (a: string, b: string) => Promise<void>;
|
||||
let toBeDecorated: AsyncFnMock<typeof decorated>;
|
||||
let decorated: (a: string, b: string) => Promise<number> | Promise<void>;
|
||||
let toBeDecorated: AsyncFnMock<(a: string, b: string) => number>;
|
||||
|
||||
beforeEach(() => {
|
||||
toBeDecorated = asyncFn();
|
||||
@ -68,7 +68,7 @@ describe("with-error-suppression", () => {
|
||||
});
|
||||
|
||||
describe("when called", () => {
|
||||
let returnValuePromise: Promise<void>;
|
||||
let returnValuePromise: Promise<number> | Promise<void>;
|
||||
|
||||
beforeEach(() => {
|
||||
returnValuePromise = decorated("some-parameter", "some-other-parameter");
|
||||
@ -92,12 +92,12 @@ describe("with-error-suppression", () => {
|
||||
expect(returnValue).toBeUndefined();
|
||||
});
|
||||
|
||||
it("when call resolves, resolves with nothing", async () => {
|
||||
await toBeDecorated.resolve(undefined);
|
||||
it("when call resolves, resolves with the value", async () => {
|
||||
await toBeDecorated.resolve(42);
|
||||
|
||||
const returnValue = await returnValuePromise;
|
||||
|
||||
expect(returnValue).toBeUndefined();
|
||||
expect(returnValue).toBe(42);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -4,8 +4,8 @@
|
||||
*/
|
||||
import { noop } from "lodash/fp";
|
||||
|
||||
export function withErrorSuppression<TDecorated extends (...args: any[]) => Promise<void>>(toBeDecorated: TDecorated): (...args: Parameters<TDecorated>) => Promise<void>;
|
||||
export function withErrorSuppression<TDecorated extends (...args: any[]) => void>(toBeDecorated: TDecorated): (...args: Parameters<TDecorated>) => void;
|
||||
export function withErrorSuppression<TDecorated extends (...args: any[]) => Promise<any>>(toBeDecorated: TDecorated): (...args: Parameters<TDecorated>) => ReturnType<TDecorated> | Promise<void>;
|
||||
export function withErrorSuppression<TDecorated extends (...args: any[]) => any>(toBeDecorated: TDecorated): (...args: Parameters<TDecorated>) => ReturnType<TDecorated> | void;
|
||||
|
||||
export function withErrorSuppression(toBeDecorated: any) {
|
||||
return (...args: any[]) => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user