File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,9 @@ function Multiaddr (addr) {
28
28
}
29
29
30
30
// default
31
- addr = addr == null ? '' : addr
31
+ if ( addr == null ) {
32
+ addr = ''
33
+ }
32
34
33
35
if ( addr instanceof Buffer ) {
34
36
/**
Original file line number Diff line number Diff line change @@ -40,8 +40,18 @@ describe('construction', () => {
40
40
expect ( multiaddr ( '' ) . toString ( ) ) . to . equal ( '/' )
41
41
} )
42
42
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 )
45
55
} )
46
56
47
57
it ( 'throws on falsy non string or buffer' , ( ) => {
You can’t perform that action at this time.
0 commit comments