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
692692added: v0.1.21
693693changes:
694694 - 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.
698697-->
699698* ` value ` {any}
700699* ` message ` {any}
@@ -707,6 +706,8 @@ property set equal to the value of the `message` parameter. If the `message`
707706parameter is ` undefined ` , a default error message is assigned. If the ` message `
708707parameter is an instance of an [ ` Error ` ] [ ] then it will be thrown instead of the
709708` 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".
710711
711712Be aware that in the ` repl ` the error message will be different to the one
712713thrown in a file! See below for further details.
@@ -719,6 +720,10 @@ assert.ok(true);
719720assert .ok (1 );
720721// OK
721722
723+ assert .ok ();
724+ // throws:
725+ // "AssertionError: No value argument passed to `assert.ok`.
726+
722727assert .ok (false , ' it\' s false' );
723728// throws "AssertionError: it's false"
724729
Original file line number Diff line number Diff line change @@ -137,11 +137,10 @@ function getBuffer(fd, assertLine) {
137137function innerOk ( args , fn ) {
138138 var [ value , message ] = args ;
139139
140- if ( args . length === 0 )
141- throw new TypeError ( 'ERR_MISSING_ARGS' , 'value' ) ;
142-
143140 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 ) {
145144 // Use the call as error message if possible.
146145 // This does not work with e.g. the repl.
147146 const err = new Error ( ) ;
Original file line number Diff line number Diff line change @@ -733,18 +733,18 @@ common.expectsError(
733733 assert . equal ( assert . notDeepEqual , assert . notDeepStrictEqual ) ;
734734 assert . equal ( Object . keys ( assert ) . length , Object . keys ( a ) . length ) ;
735735 assert ( 7 ) ;
736- common . expectsError (
737- ( ) => assert ( ) ,
736+ assert . throws (
737+ ( ) => assert ( ... [ ] ) ,
738738 {
739- code : 'ERR_MISSING_ARGS ' ,
740- type : TypeError
739+ message : 'No value argument passed to `assert.ok()` ' ,
740+ name : 'AssertionError [ERR_ASSERTION]'
741741 }
742742 ) ;
743- common . expectsError (
743+ assert . throws (
744744 ( ) => a ( ) ,
745745 {
746- code : 'ERR_MISSING_ARGS ' ,
747- type : TypeError
746+ message : 'No value argument passed to `assert.ok()` ' ,
747+ name : 'AssertionError [ERR_ASSERTION]'
748748 }
749749 ) ;
750750
You can’t perform that action at this time.
0 commit comments