From 0749e12bbae0b01cdda3a857f5399009aef58e8a Mon Sep 17 00:00:00 2001 From: Jamie Mason Date: Tue, 7 Nov 2017 22:49:33 +0000 Subject: [PATCH] Jest matchers can accept many arguments --- types/jest/index.d.ts | 3 ++- types/jest/jest-tests.ts | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/types/jest/index.d.ts b/types/jest/index.d.ts index 18b3db361a..1b8d137094 100644 --- a/types/jest/index.d.ts +++ b/types/jest/index.d.ts @@ -8,6 +8,7 @@ // Allan Lukwago // Ika // Waseem Dahman +// Jamie Mason // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -240,7 +241,7 @@ declare namespace jest { } interface ExpectExtendMap { - [key: string]: (this: MatcherUtils, received: any, actual: any) => { message(): string, pass: boolean }; + [key: string]: (this: MatcherUtils, received: any, ...actual: any[]) => { message(): string, pass: boolean }; } interface SnapshotSerializerOptions { diff --git a/types/jest/jest-tests.ts b/types/jest/jest-tests.ts index d2b4d95a0e..aca5021f1b 100644 --- a/types/jest/jest-tests.ts +++ b/types/jest/jest-tests.ts @@ -259,6 +259,12 @@ describe('Extending extend', () => { () => `expected ${received} ${pass ? 'not ' : ''} to be ${actual}`; return { message, pass }; }, + toBeVariadicMatcher(received: any, floor: number, ceiling: number) { + const pass = received >= floor && received <= ceiling; + const message = + () => `expected ${received} ${pass ? 'not ' : ''} to be within range ${floor}-${ceiling}`; + return { message, pass }; + }, toBeTest(received: any, actual: any) { this.utils.ensureNoExpected(received); this.utils.ensureActualIsNumber(received);