{"version":3,"sources":["../src/expect/index.ts","../src/expect/renderStreamMatchers.ts","../src/assertable.ts"],"sourcesContent":["import {expect} from 'expect'\nimport {\n  toRerender,\n  toRenderExactlyTimes,\n  type RenderStreamMatchers,\n} from './renderStreamMatchers.js'\n\nexpect.extend({\n  toRerender,\n  toRenderExactlyTimes,\n})\n\ndeclare module 'expect' {\n  // eslint-disable-next-line @typescript-eslint/no-empty-interface\n  interface Matchers<R extends void | Promise<void>, T = unknown>\n    extends RenderStreamMatchers<R, T> {}\n}\n","import {MatcherContext, type MatcherFunction} from 'expect'\nimport {\n  WaitForRenderTimeoutError,\n  type Assertable,\n  type NextRenderOptions,\n  type RenderStream,\n} from '@testing-library/react-render-stream'\n// explicitly imported the symbol from the internal file\n// this will bundle the `Symbol.for` call twice, but we keep it private\nimport {assertableSymbol} from '../assertable.js'\n\nexport interface RenderStreamMatchers<R = void, T = {}> {\n  toRerender: T extends RenderStream<any> | Assertable\n    ? (options?: NextRenderOptions) => Promise<R>\n    : {\n        error: 'matcher needs to be called on a `takeRender` function, `takeSnapshot` function or `RenderStream` instance'\n      }\n\n  toRenderExactlyTimes: T extends RenderStream<any> | Assertable\n    ? (count: number, options?: NextRenderOptions) => Promise<R>\n    : {\n        error: 'matcher needs to be called on a `takeRender` function, `takeSnapshot` function or `RenderStream` instance'\n      }\n}\n\nexport const toRerender: MatcherFunction<[options?: NextRenderOptions]> =\n  async function toRerender(this: MatcherContext, actual, options) {\n    const _stream = actual as RenderStream<any> | Assertable\n    const stream =\n      assertableSymbol in _stream ? _stream[assertableSymbol] : _stream\n    const hint = this.utils.matcherHint('toRerender', undefined, undefined, {\n      isNot: this.isNot,\n    })\n    let pass = true\n    try {\n      await stream.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\\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 = new Error()\n\nexport const toRenderExactlyTimes: MatcherFunction<\n  [times: number, options?: NextRenderOptions]\n> = async function toRenderExactlyTimes(\n  this: MatcherContext,\n  actual,\n  times,\n  optionsPerRender,\n) {\n  const _stream = actual as RenderStream<any> | Assertable\n  const stream =\n    assertableSymbol in _stream ? _stream[assertableSymbol] : _stream\n  const options = {timeout: 100, ...optionsPerRender}\n  const hint = this.utils.matcherHint(\n    'toRenderExactlyTimes',\n    undefined,\n    undefined,\n    {isNot: this.isNot},\n  )\n  let pass = true\n  try {\n    if (stream.totalRenderCount() > times) {\n      throw failed\n    }\n    try {\n      while (stream.totalRenderCount() < times) {\n        // eslint-disable-next-line no-await-in-loop\n        await stream.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 stream.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        `${\n          hint\n        }\\n\\nExpected component to${pass ? ' not' : ''} render exactly ${times} times.` +\n        `\\nIt rendered ${stream.totalRenderCount()} times.`\n      )\n    },\n  }\n}\n","import {type RenderStream} from './renderStream/createRenderStream.js'\n\nexport const assertableSymbol = Symbol.for(\n  '@testing-library/react-render-stream:assertable',\n)\n\n/**\n * A function or object that can be used in assertions, like e.g.\n ```ts\n expect(assertable).toRerender()\n expect(assertable).not.toRerender()\n expect(assertable).toRenderExactlyTimes(3)\n ```\n */\nexport type Assertable = {\n  [assertableSymbol]: RenderStream<any, any>\n}\n\nexport function markAssertable<T extends {}>(\n  assertable: T,\n  stream: RenderStream<any, any>,\n): T &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