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ForRenderTimeoutError } from \"../internal/index.js\";\nimport type {\n NextRenderOptions,\n Profiler,\n ProfiledComponent,\n ProfiledHook,\n} from \"../internal/index.js\";\n\nexport const toRerender: MatcherFunction<[options?: NextRenderOptions]> =\n async function (actual, options) {\n const _profiler = actual as\n | Profiler\n | ProfiledComponent\n | ProfiledHook;\n const profiler = \"Profiler\" in _profiler ? _profiler.Profiler : _profiler;\n const hint = this.utils.matcherHint(\"toRerender\", \"ProfiledComponent\", \"\");\n let pass = true;\n try {\n await profiler.peekRender({ timeout: 100, ...options });\n } catch (e) {\n if (e instanceof WaitForRenderTimeoutError) {\n pass = false;\n } else {\n throw e;\n }\n }\n\n return {\n pass,\n message() {\n return (\n hint +\n `\\n\\nExpected component to${pass ? \" not\" : \"\"} rerender, ` +\n `but it did${pass ? \"\" : \" not\"}.`\n );\n },\n };\n };\n\n/** to be thrown to \"break\" test execution and fail it */\nconst failed = {};\n\nexport const toRenderExactlyTimes: MatcherFunction<\n [times: number, options?: NextRenderOptions]\n> = async function (actual, times, optionsPerRender) {\n const _profiler = actual as\n | Profiler\n | ProfiledComponent\n | ProfiledHook;\n const profiler = \"Profiler\" in _profiler ? _profiler.Profiler : _profiler;\n const options = { timeout: 100, ...optionsPerRender };\n const hint = this.utils.matcherHint(\"toRenderExactlyTimes\");\n let pass = true;\n try {\n if (profiler.totalRenderCount() > times) {\n throw failed;\n }\n try {\n while (profiler.totalRenderCount() < times) {\n await profiler.waitForNextRender(options);\n }\n } catch (e) {\n // timeouts here should just fail the test, rethrow other errors\n throw e instanceof WaitForRenderTimeoutError ? failed : e;\n }\n try {\n await profiler.waitForNextRender(options);\n } catch (e) {\n // we are expecting a timeout here, so swallow that error, rethrow others\n if (!(e instanceof WaitForRenderTimeoutError)) {\n throw e;\n }\n }\n } catch (e) {\n if (e === failed) {\n pass = false;\n } else {\n throw e;\n }\n }\n return {\n pass,\n message() {\n return (\n hint +\n ` Expected component to${pass ? \" not\" : \"\"} render exactly ${times}.` +\n ` It rendered ${profiler.totalRenderCount()} times.`\n );\n },\n };\n};\n"]}