Skip to content

Commit

Permalink
Support custom assertion messages (#204)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
marlun78 and sindresorhus authored Apr 23, 2024
1 parent 664b907 commit f2e5834
Show file tree
Hide file tree
Showing 3 changed files with 634 additions and 268 deletions.
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ assert.string(2);
//=> Error: Expected value which is `string`, received value of type `number`.
```

Assertions (except `assertAll` and `assertAny`) also support an optional custom error message.

```js
import {assert} from '@sindresorhus/is';

assert.nonEmptyString(process.env.API_URL, 'The API_URL environment variable is required.');
//=> Error: The API_URL environment variable is required.
```

And with TypeScript:

```ts
Expand Down
Loading

0 comments on commit f2e5834

Please sign in to comment.