Skip to content

Commit

Permalink
Update matcher to allow ProfiledComponent as acceptable value
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Nov 28, 2023
1 parent 01d6696 commit 5c76e4f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/testing/matchers/ProfiledComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> | ProfiledHook<any, any>;
const _profiler = actual as
| Profiler<any>
| ProfiledComponent<any, any>
| ProfiledHook<any, any>;
const profiler = "Profiler" in _profiler ? _profiler.Profiler : _profiler;
const hint = this.utils.matcherHint("toRerender", "ProfiledComponent", "");
let pass = true;
Expand Down Expand Up @@ -40,7 +44,10 @@ const failed = {};
export const toRenderExactlyTimes: MatcherFunction<
[times: number, options?: NextRenderOptions]
> = async function (actual, times, optionsPerRender) {
const _profiler = actual as Profiler<any> | ProfiledHook<any, any>;
const _profiler = actual as
| Profiler<any>
| ProfiledComponent<any, any>
| ProfiledHook<any, any>;
const profiler = "Profiler" in _profiler ? _profiler.Profiler : _profiler;
const options = { timeout: 100, ...optionsPerRender };
const hint = this.utils.matcherHint("toRenderExactlyTimes");
Expand Down
11 changes: 9 additions & 2 deletions src/testing/matchers/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
import {
NextRenderOptions,
Profiler,
ProfiledComponent,
ProfiledHook,
} from "../internal/index.js";

Expand All @@ -29,11 +30,17 @@ interface ApolloCustomMatchers<R = void, T = {}> {
) => R
: { error: "matcher needs to be called on an ApolloClient instance" };

toRerender: T extends Profiler<any, any> | ProfiledHook<any, any>
toRerender: T extends
| Profiler<any, any>
| ProfiledComponent<any, any>
| ProfiledHook<any, any>
? (options?: NextRenderOptions) => Promise<R>
: { error: "matcher needs to be called on a ProfiledComponent instance" };

toRenderExactlyTimes: T extends Profiler<any, any> | ProfiledHook<any, any>
toRenderExactlyTimes: T extends
| Profiler<any, any>
| ProfiledComponent<any, any>
| ProfiledHook<any, any>
? (count: number, options?: NextRenderOptions) => Promise<R>
: { error: "matcher needs to be called on a ProfiledComponent instance" };
}
Expand Down

0 comments on commit 5c76e4f

Please sign in to comment.