> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# detectAsyncLeaks


[Added in v0.10.0](https://github.com/web-infra-dev/rstest/releases/tag/v0.10.0)

- **Type:** `boolean`
- **Default:** `false`
- **CLI:** `--detectAsyncLeaks`

Detect async resources that are still active after a test file finishes, such as timers that were not cleaned up.

This option uses Node.js `async_hooks`, so it may slow down tests. It is intended for debugging leaks and is not recommended for regular test runs.


**CLI**

```bash
npx rstest --detectAsyncLeaks
```


**rstest.config.ts**

```ts
import { defineConfig } from '@rstest/core';

export default defineConfig({
  detectAsyncLeaks: true,
});
```


## Example

The following test leaks an interval:

```ts
import { expect, it } from '@rstest/core';

it('leaks a timer', () => {
  setInterval(() => {}, 1000);
  expect(1).toBe(1);
});
```

When `detectAsyncLeaks` is enabled, Rstest fails the test file and reports the resource type and creation stack:

```bash
AsyncLeakError: Detected async leak: Timeout was still active after leaks a timer finished.
```

Clean up async resources before the test finishes to avoid the error:

```ts
import { expect, it } from '@rstest/core';

it('cleans up a timer', () => {
  const timer = setInterval(() => {}, 1000);
  clearInterval(timer);
  expect(1).toBe(1);
});
```
