You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One downside to `common.expectsError()` is that it increases the
abstractions people have to learn about in order to work with even
simple tests. Whereas before, all they had to know about is
`assert.throws()`, now they have to *also* know about
`common.expectsError()`. This is very different (IMO) from
`common.mustCall()` in that the latter has an intuitively understandable
name, accepts arguments as one would expect, and (in most cases) doesn't
actually require reading documentation or code to figure out what it's
doing. With `common.expectsError()`, there's a fair bit of magic. Like,
it's not obvious what the first argument would be. Or the second. Or the
third. You just have to know.
This PR changes the arguments accepted by `common.expectsError()` to a
single settings object. Someone coming across this has a hope of
understanding what's going on without reading source or docs:
```js
const validatorFunction = common.expectsError({code: 'ELOOP',
type: Error,
message: 'foo'});
```
This, by comparison, is harder to grok:
```js
const validatorFunction = common.expectsError('ELOOP',
Error,
'foo');
```
And this is especially wat-inducing:
```js
common.expectsError(undefined, undefined, 'looped doodad found');
```
It's likely that only people who work with tests frequently can be
expected to remember the three arguments and their order. By comparison,
remembering that the error code is `code` and the message is `message`
might be manageable.
PR-URL: #11512
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Reviewed-By: Yuta Hiroto <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
or [<RegExp>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
197
-
if a string is provided for `message`, expected error must have it for its
198
-
`message` property; if a regular expression is provided for `message`, the
199
-
regular expression must match the `message` property of the expected error
or [<RegExp>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
199
+
if a string is provided for `message`, expected error must have it for its
200
+
`message` property; if a regular expression is provided for `message`, the
201
+
regular expression must match the `message` property of the expected error
200
202
201
203
* return function suitable for use as a validation function passed as the second
0 commit comments