From 496ccfe4965f357a4b4920e33dc4bc2c6ac523f8 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Mon, 27 Nov 2023 22:19:53 -0700 Subject: [PATCH] Update matcher to allow ProfiledComponent as acceptable value --- src/testing/matchers/ProfiledComponent.ts | 11 +++++++++-- src/testing/matchers/index.d.ts | 10 ++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/testing/matchers/ProfiledComponent.ts b/src/testing/matchers/ProfiledComponent.ts index 2ed110bc3a3..435c24a29a6 100644 --- a/src/testing/matchers/ProfiledComponent.ts +++ b/src/testing/matchers/ProfiledComponent.ts @@ -3,12 +3,16 @@ import { WaitForRenderTimeoutError } from "../internal/index.js"; import type { NextRenderOptions, Profiler, + ProfiledComponent, ProfiledHook, } from "../internal/index.js"; export const toRerender: MatcherFunction<[options?: NextRenderOptions]> = async function (actual, options) { - const _profiler = actual as Profiler | ProfiledHook; + const _profiler = actual as + | Profiler + | ProfiledComponent + | ProfiledHook; const profiler = "Profiler" in _profiler ? _profiler.Profiler : _profiler; const hint = this.utils.matcherHint("toRerender", "ProfiledComponent", ""); let pass = true; @@ -40,7 +44,10 @@ const failed = {}; export const toRenderExactlyTimes: MatcherFunction< [times: number, options?: NextRenderOptions] > = async function (actual, times, optionsPerRender) { - const _profiler = actual as Profiler | ProfiledHook; + const _profiler = actual as + | Profiler + | ProfiledComponent + | ProfiledHook; const profiler = "Profiler" in _profiler ? _profiler.Profiler : _profiler; const options = { timeout: 100, ...optionsPerRender }; const hint = this.utils.matcherHint("toRenderExactlyTimes"); diff --git a/src/testing/matchers/index.d.ts b/src/testing/matchers/index.d.ts index 6f8cb02efd6..f39f96bc69b 100644 --- a/src/testing/matchers/index.d.ts +++ b/src/testing/matchers/index.d.ts @@ -29,11 +29,17 @@ interface ApolloCustomMatchers { ) => R : { error: "matcher needs to be called on an ApolloClient instance" }; - toRerender: T extends Profiler | ProfiledHook + toRerender: T extends + | Profiler + | ProfiledComponent + | ProfiledHook ? (options?: NextRenderOptions) => Promise : { error: "matcher needs to be called on a ProfiledComponent instance" }; - toRenderExactlyTimes: T extends Profiler | ProfiledHook + toRenderExactlyTimes: T extends + | Profiler + | ProfiledComponent + | ProfiledHook ? (count: number, options?: NextRenderOptions) => Promise : { error: "matcher needs to be called on a ProfiledComponent instance" }; }