---
url: /test-inventory/api/functions/filterInventory.md
---
# Function: filterInventory()

> **filterInventory**(`inventory`, `filter`): [`Inventory`](../interfaces/Inventory.md)

Keeps the tests that pass every condition of the filter; a list keeps a test that has any of its values. The
result describes only those tests: their files, the describes around them, their diagnostics, and a summary
counted over them. Files without any tests stay, with their diagnostics, since tests may be missing from them.
`summary.fileCount` stays the number of files scanned.

Throws a `TypeError` for an invalid filter.

## Parameters

### inventory

[`Inventory`](../interfaces/Inventory.md)

### filter

#### states?

(`"active"` | `"skip"` | `"fixme"` | `"todo"` | `"expectedToFail"` | `"notLoaded"`)\[]

Keeps tests in one of these states.

#### tags?

`string`\[]

Keeps tests with one of these tags, as the output writes them.

#### grep?

`string`

Keeps tests whose `fullName` matches this regular expression, ignoring case, as Playwright's `--grep` does.

#### only?

`boolean`

Keeps tests that use `.only`, or are inside a describe that does.

#### withoutReason?

`boolean`

Keeps tests that don't run and give no reason. Tests in a file the runner refuses are left out.

## Returns

[`Inventory`](../interfaces/Inventory.md)
