Support custom assertion messages (#204)
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
This commit is contained in:
parent
664b9077e1
commit
f2e5834421
3 changed files with 634 additions and 268 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue