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", () => {
|
describe("given decorated async function", () => {
|
||||||
let decorated: (a: string, b: string) => Promise<void>;
|
let decorated: (a: string, b: string) => Promise<number> | Promise<void>;
|
||||||
let toBeDecorated: AsyncFnMock<typeof decorated>;
|
let toBeDecorated: AsyncFnMock<(a: string, b: string) => number>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
toBeDecorated = asyncFn();
|
toBeDecorated = asyncFn();
|
||||||
@ -68,7 +68,7 @@ describe("with-error-suppression", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("when called", () => {
|
describe("when called", () => {
|
||||||
let returnValuePromise: Promise<void>;
|
let returnValuePromise: Promise<number> | Promise<void>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
returnValuePromise = decorated("some-parameter", "some-other-parameter");
|
returnValuePromise = decorated("some-parameter", "some-other-parameter");
|
||||||
@ -92,12 +92,12 @@ describe("with-error-suppression", () => {
|
|||||||
expect(returnValue).toBeUndefined();
|
expect(returnValue).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("when call resolves, resolves with nothing", async () => {
|
it("when call resolves, resolves with the value", async () => {
|
||||||
await toBeDecorated.resolve(undefined);
|
await toBeDecorated.resolve(42);
|
||||||
|
|
||||||
const returnValue = await returnValuePromise;
|
const returnValue = await returnValuePromise;
|
||||||
|
|
||||||
expect(returnValue).toBeUndefined();
|
expect(returnValue).toBe(42);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -4,8 +4,8 @@
|
|||||||
*/
|
*/
|
||||||
import { noop } from "lodash/fp";
|
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[]) => Promise<any>>(toBeDecorated: TDecorated): (...args: Parameters<TDecorated>) => ReturnType<TDecorated> | Promise<void>;
|
||||||
export function withErrorSuppression<TDecorated extends (...args: any[]) => void>(toBeDecorated: TDecorated): (...args: Parameters<TDecorated>) => void;
|
export function withErrorSuppression<TDecorated extends (...args: any[]) => any>(toBeDecorated: TDecorated): (...args: Parameters<TDecorated>) => ReturnType<TDecorated> | void;
|
||||||
|
|
||||||
export function withErrorSuppression(toBeDecorated: any) {
|
export function withErrorSuppression(toBeDecorated: any) {
|
||||||
return (...args: any[]) => {
|
return (...args: any[]) => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user