[API reference](https://evolu.dev/docs/api-reference) › [@evolu/common](https://evolu.dev/docs/api-reference/common) › [Assert](https://evolu.dev/docs/api-reference/common/Assert) › assertThrows

## Call Signature

```ts
function assertThrows(
  run: () => unknown,
  assertThrown: (thrown: unknown) => void,
): void;
```

Defined in: [packages/common/src/Assert.ts:372](https://github.com/evoluhq/evolu/blob/ecbac001e0c18bbc45b44715f49ecc3a768c5ec9/packages/common/src/Assert.ts#L372)

Asserts that a function throws the expected value.

Expected values use [assertEqual](https://evolu.dev/docs/api-reference/common/Assert/functions/assertEqual) semantics. To perform several or
specialized assertions, pass an assertion function that receives the thrown
value and returns nothing. Returning a predicate result fails. Use
[assertThrowsSame](https://evolu.dev/docs/api-reference/common/Assert/functions/assertThrowsSame) for SameValue or reference identity and
[assertThrowsInstanceOf](https://evolu.dev/docs/api-reference/common/Assert/functions/assertThrowsInstanceOf) for a runtime type.

Because JavaScript permits throwing functions, a function second argument is
always treated as an assertion function. Use `assertThrowsSame` to assert
that a particular function was thrown.

### Example

```ts

assertThrows(
  () => {
    // oxlint-disable-next-line eslint/no-throw-literal, typescript/only-throw-error -- Exercise arbitrary thrown values.
    throw { type: "ExpectedFailure", value: 42 };
  },
  { type: "ExpectedFailure", value: 42 },
);
```

## Call Signature

```ts
function assertThrows(run: () => unknown, expected: unknown): void;
```

Defined in: [packages/common/src/Assert.ts:376](https://github.com/evoluhq/evolu/blob/ecbac001e0c18bbc45b44715f49ecc3a768c5ec9/packages/common/src/Assert.ts#L376)

Asserts that a function throws the expected value.

Expected values use [assertEqual](https://evolu.dev/docs/api-reference/common/Assert/functions/assertEqual) semantics. To perform several or
specialized assertions, pass an assertion function that receives the thrown
value and returns nothing. Returning a predicate result fails. Use
[assertThrowsSame](https://evolu.dev/docs/api-reference/common/Assert/functions/assertThrowsSame) for SameValue or reference identity and
[assertThrowsInstanceOf](https://evolu.dev/docs/api-reference/common/Assert/functions/assertThrowsInstanceOf) for a runtime type.

Because JavaScript permits throwing functions, a function second argument is
always treated as an assertion function. Use `assertThrowsSame` to assert
that a particular function was thrown.

### Example

```ts

assertThrows(
  () => {
    // oxlint-disable-next-line eslint/no-throw-literal, typescript/only-throw-error -- Exercise arbitrary thrown values.
    throw { type: "ExpectedFailure", value: 42 };
  },
  { type: "ExpectedFailure", value: 42 },
);
```