{"version":3,"file":"ngxtension-testing.mjs","sources":["../../../../libs/ngxtension/testing/src/act.ts","../../../../libs/ngxtension/testing/src/waitfor.ts","../../../../libs/ngxtension/testing/src/ngxtension-testing.ts"],"sourcesContent":["import { ApplicationRef } from '@angular/core';\nimport { TestBed } from '@angular/core/testing';\n\n/**\n * Executes a function and waits for the application to stabilize.\n *\n * This utility helps in testing async state transitions by ensuring that\n * any scheduled effects or microtasks are processed before the promise resolves.\n *\n * @param fn The function to execute.\n * @returns A promise that resolves to the result of the function after stability.\n */\nexport async function act<T>(fn: () => T): Promise<T> {\n\tconst result = fn();\n\tawait TestBed.inject(ApplicationRef).whenStable();\n\treturn result;\n}\n","import { TestBed } from '@angular/core/testing';\n\nexport interface WaitForOptions {\n\ttimeout?: number;\n\tinterval?: number;\n}\n\nexport interface ExpectTextOptions extends WaitForOptions {\n\tcontainer?: HTMLElement;\n}\n\n/**\n * Returns a promise that resolves when the text content is found on the screen.\n *\n * @param text - The expected text content, regex, or matcher function.\n *\n * @example\n * ```ts\n * await expectText('Hello');\n * await expectText(/Hello/);\n * ```\n */\nexport async function expectText(\n\ttext: string | RegExp,\n\toptions: ExpectTextOptions = {},\n): Promise<void> {\n\t// TestBed.getFixture will be\n\tconst container =\n\t\toptions.container ||\n\t\t// The following is the implementation of TestBed.getFixture that will be introduced in Angular v22.\n\t\t(TestBed as any).INSTANCE._activeFixtures[0].nativeElement;\n\tawait waitFor(() => {\n\t\tconst content = container.textContent || '';\n\t\tif (typeof text === 'string') {\n\t\t\tif (!content.includes(text)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Expected text \"${text}\" not found in content: \"${content}\"`,\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\tif (!text.test(content)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Expected text matching ${text} not found in content: \"${content}\"`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}, options);\n}\n\n// Intentionally does not participate in fake clocks.\nconst realNow = performance.now.bind(performance);\nconst realSetTimeout = setTimeout;\n\n/**\n * @param callback - The function to execute until it succeeds or times out.\n * @param options - Optional configuration for timeout and retry interval.\n *\n * Note: the implementation of this function makes sure to not participate in fake timers,\n * so that it can be used in tests that use fake timers without being affected by them.\n */\nexport async function waitFor<T>(\n\tcallback: () => Promise<T> | T,\n\toptions: WaitForOptions = {},\n): Promise<T> {\n\tconst waitTime = options.timeout ?? 100;\n\tconst interval = options.interval ?? 0;\n\tconst stack = new Error().stack;\n\n\tconst deadline = realNow() + waitTime;\n\tlet i = 0;\n\tlet lastError: any | undefined;\n\n\twhile (true) {\n\t\ttry {\n\t\t\treturn await callback();\n\t\t} catch (cause) {\n\t\t\tlastError = cause;\n\t\t}\n\n\t\ti++;\n\n\t\tif (deadline < realNow()) {\n\t\t\tthrow Object.assign(\n\t\t\t\tnew Error(\n\t\t\t\t\t`Timed out after ${waitTime}ms and ${i} attempts. ` +\n\t\t\t\t\t\t`Last error: ${lastError?.message ?? 'condition returned false'}`,\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\tstack:\n\t\t\t\t\t\tstack +\n\t\t\t\t\t\t`Last error: ${lastError?.stack ?? 'condition returned false'}`,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\t// Guarantee a macro-task between retries.\n\t\tawait new Promise((resolve) => void realSetTimeout(resolve, interval));\n\t}\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;AAGA;;;;;;;;AAQG;AACI,eAAe,GAAG,CAAI,EAAW,EAAA;AACvC,IAAA,MAAM,MAAM,GAAG,EAAE,EAAE,CAAC;IACpB,MAAM,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,UAAU,EAAE,CAAC;AAClD,IAAA,OAAO,MAAM,CAAC;AACf;;ACLA;;;;;;;;;;AAUG;AACI,eAAe,UAAU,CAC/B,IAAqB,EACrB,UAA6B,EAAE,EAAA;;AAG/B,IAAA,MAAM,SAAS,GACd,OA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