| drainCollectedUnhandledAsyncErrors | Empties the collection window opened by startCollectingUnhandledAsyncErrors and returns what it held, leaving the window open so errors emitted afterwards keep being collected. This is what setup!setup’s beforeEach / afterEach use, rather than stopCollectingUnhandledAsyncErrors: an async error emitted in the gap between two tests (e.g. by a setTimeout the test left pending) would otherwise land on a closed window and vanish unreported. |
| emitAsyncErrorEvent | Emits an asynchronous error event. When a collection window is open (see startCollectingUnhandledAsyncErrors) the error is collected as unhandled unless it is ignored — either because shouldIgnore is true or an startAsyncErrorIgnoreContext scope is active. A registered consumer handler deliberately does not exempt the error: in production it shows the user a Notice, which is not a test asserting that the error was expected. startAsyncErrorIgnoreContext is the single, explicit opt-out. |
| errorToString | Converts an error to a string representation, including nested causes and the aggregated errors of an AggregateError, with indentation. |
| getStackTrace | Gets the current stack trace as a string, excluding the current function call. |
| isAsyncErrorIgnoreContextActive | Checks whether an startAsyncErrorIgnoreContext scope is currently active. |
| printError | Prints an error to the console, including nested causes and optional ANSI sequence clearing. |
| registerAsyncErrorEventHandler | Registers an event handler for asynchronous errors. Registering a handler does not mark the errors it receives as expected — see emitAsyncErrorEvent. A test that deliberately triggers an async error opens a startAsyncErrorIgnoreContext scope regardless of who is listening. |
| startAsyncErrorIgnoreContext | Opens an ignore context in which async errors are treated as expected rather than unhandled, so the test harness does not fail the test. While the returned disposable is held, an async error emitted directly (see emitAsyncErrorEvent) is not collected as unhandled. Crucially, a fire-and-forget operation scheduled within the scope (e.g. via async!invokeAsyncSafely) is also ignored when it later rejects — even after the scope has exited — because async!addErrorHandler captures the active ignore context at schedule time. A test therefore does not need to drain the operation itself: ts it('does not fail', () => \{ using _ = startAsyncErrorIgnoreContext(); invokeAsyncSafely(() => Promise.reject(new Error('deliberately swallowed'))); \}); Contexts nest; the ignore only ends once every open context has been disposed. |
| startCollectingUnhandledAsyncErrors | Opens a window in which async errors emitted outside an ignore context are collected as unhandled (see emitAsyncErrorEvent), discarding anything collected by a previous window. Intended for the test harness only: the per-test setup opens a window before each test and empties it after each test via drainCollectedUnhandledAsyncErrors, closing it for good with stopCollectingUnhandledAsyncErrors once the file’s last test has run. In production no window is open, so emitting an async error carries no bookkeeping overhead. |
| stopCollectingUnhandledAsyncErrors | Closes the window opened by startCollectingUnhandledAsyncErrors and returns the unhandled async errors collected while it was open. Use drainCollectedUnhandledAsyncErrors instead wherever collection must continue afterwards — once the window is closed, a later async error is not collected by anyone. |
| throwExpression | Throws an error with the specified message. |