From 9a3839b63b4c1ecc0ca8ffa88ce2d88fa5d203ae Mon Sep 17 00:00:00 2001 From: Dobes Vandermeer Date: Wed, 27 Jun 2018 10:34:56 -0700 Subject: [PATCH] Allow async extension functions According to http://jestjs.io/docs/en/expect.html#expectextendmatchers > expect.extends also supports async matchers. Async matchers return a Promise so you will need to await the returned value. Let's use an example matcher to illustrate the usage of them. We are going to implement a very similar matcher than toBeDivisibleBy, only difference is that the divisible number is going to be pulled from an external source. This updates the typings of `ExpectExtendMap` to allow a `Promise` to be returned. --- types/jest/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/jest/index.d.ts b/types/jest/index.d.ts index 432ba6f36f..6f1e8d4401 100644 --- a/types/jest/index.d.ts +++ b/types/jest/index.d.ts @@ -269,7 +269,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 } | Promise<{ message(): string, pass: boolean }>; } interface SnapshotSerializerOptions {