Jest matchers can accept many arguments

This commit is contained in:
Jamie Mason
2017-11-09 22:24:44 +00:00
committed by Jamie Mason
parent 31ace05ea4
commit 0749e12bba
2 changed files with 8 additions and 1 deletions
+2 -1
View File
@@ -8,6 +8,7 @@
// Allan Lukwago <https://github.com/epicallan>
// Ika <https://github.com/ikatyang>
// Waseem Dahman <https://github.com/wsmd>
// Jamie Mason <https://github.com/JamieMason>
// 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 {
+6
View File
@@ -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);