File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,9 @@ function Multiaddr (addr) {
2828 }
2929
3030 // default
31- addr = addr || ''
31+ if ( addr == null ) {
32+ addr = ''
33+ }
3234
3335 if ( addr instanceof Buffer ) {
3436 /**
Original file line number Diff line number Diff line change @@ -40,8 +40,25 @@ describe('construction', () => {
4040 expect ( multiaddr ( '' ) . toString ( ) ) . to . equal ( '/' )
4141 } )
4242
43- it ( 'throws on non string or buffer' , ( ) => {
44- expect ( ( ) => multiaddr ( { } ) ) . to . throw ( / a d d r m u s t b e a s t r i n g / )
43+ it ( 'null/undefined construct still works' , ( ) => {
44+ expect ( multiaddr ( ) . toString ( ) ) . to . equal ( '/' )
45+ expect ( multiaddr ( null ) . toString ( ) ) . to . equal ( '/' )
46+ expect ( multiaddr ( undefined ) . toString ( ) ) . to . equal ( '/' )
47+ } )
48+
49+ it ( 'throws on truthy non string or buffer' , ( ) => {
50+ const errRegex = / a d d r m u s t b e a s t r i n g /
51+ expect ( ( ) => multiaddr ( { } ) ) . to . throw ( errRegex )
52+ expect ( ( ) => multiaddr ( [ ] ) ) . to . throw ( errRegex )
53+ expect ( ( ) => multiaddr ( 138 ) ) . to . throw ( errRegex )
54+ expect ( ( ) => multiaddr ( true ) ) . to . throw ( errRegex )
55+ } )
56+
57+ it ( 'throws on falsy non string or buffer' , ( ) => {
58+ const errRegex = / a d d r m u s t b e a s t r i n g /
59+ expect ( ( ) => multiaddr ( NaN ) ) . to . throw ( errRegex )
60+ expect ( ( ) => multiaddr ( false ) ) . to . throw ( errRegex )
61+ expect ( ( ) => multiaddr ( 0 ) ) . to . throw ( errRegex )
4562 } )
4663} )
4764
You can’t perform that action at this time.
0 commit comments