File tree Expand file tree Collapse file tree 3 files changed +18
-14
lines changed Expand file tree Collapse file tree 3 files changed +18
-14
lines changed Original file line number Diff line number Diff line change @@ -692,9 +692,8 @@ parameter is an instance of an [`Error`][] then it will be thrown instead of the
692
692
added: v0.1.21
693
693
changes:
694
694
- version: REPLACEME
695
- pr-url: https://github.com/nodejs/node/pull/17581
696
- description: assert.ok() will throw a `ERR_MISSING_ARGS` error.
697
- Use assert.fail() instead.
695
+ pr-url: https://github.com/nodejs/node/pull/REPLACEME
696
+ description: assert.ok() (no arguments) will now use a predefined error msg.
698
697
-->
699
698
* ` value ` {any}
700
699
* ` message ` {any}
@@ -707,6 +706,8 @@ property set equal to the value of the `message` parameter. If the `message`
707
706
parameter is ` undefined ` , a default error message is assigned. If the ` message `
708
707
parameter is an instance of an [ ` Error ` ] [ ] then it will be thrown instead of the
709
708
` AssertionError ` .
709
+ If no arguments are passed in at all ` message ` will be set to the string:
710
+ "No value argument passed to assert.ok".
710
711
711
712
Be aware that in the ` repl ` the error message will be different to the one
712
713
thrown in a file! See below for further details.
@@ -719,6 +720,10 @@ assert.ok(true);
719
720
assert .ok (1 );
720
721
// OK
721
722
723
+ assert .ok ();
724
+ // throws:
725
+ // "AssertionError: No value argument passed to `assert.ok`.
726
+
722
727
assert .ok (false , ' it\' s false' );
723
728
// throws "AssertionError: it's false"
724
729
Original file line number Diff line number Diff line change @@ -137,11 +137,10 @@ function getBuffer(fd, assertLine) {
137
137
function innerOk ( args , fn ) {
138
138
var [ value , message ] = args ;
139
139
140
- if ( args . length === 0 )
141
- throw new TypeError ( 'ERR_MISSING_ARGS' , 'value' ) ;
142
-
143
140
if ( ! value ) {
144
- if ( message == null ) {
141
+ if ( args . length === 0 ) {
142
+ message = 'No value argument passed to `assert.ok()`' ;
143
+ } else if ( message == null ) {
145
144
// Use the call as error message if possible.
146
145
// This does not work with e.g. the repl.
147
146
const err = new Error ( ) ;
Original file line number Diff line number Diff line change @@ -733,18 +733,18 @@ common.expectsError(
733
733
assert . equal ( assert . notDeepEqual , assert . notDeepStrictEqual ) ;
734
734
assert . equal ( Object . keys ( assert ) . length , Object . keys ( a ) . length ) ;
735
735
assert ( 7 ) ;
736
- common . expectsError (
737
- ( ) => assert ( ) ,
736
+ assert . throws (
737
+ ( ) => assert ( ... [ ] ) ,
738
738
{
739
- code : 'ERR_MISSING_ARGS ' ,
740
- type : TypeError
739
+ message : 'No value argument passed to `assert.ok()` ' ,
740
+ name : 'AssertionError [ERR_ASSERTION]'
741
741
}
742
742
) ;
743
- common . expectsError (
743
+ assert . throws (
744
744
( ) => a ( ) ,
745
745
{
746
- code : 'ERR_MISSING_ARGS ' ,
747
- type : TypeError
746
+ message : 'No value argument passed to `assert.ok()` ' ,
747
+ name : 'AssertionError [ERR_ASSERTION]'
748
748
}
749
749
) ;
750
750
You can’t perform that action at this time.
0 commit comments