@@ -14,6 +14,60 @@ function withLimits (limits, fields) {
1414}
1515
1616describe ( 'Error Handling' , function ( ) {
17+ const invalidPlainObj = [ 'not an plain object' , [ 'storage' , 'limits' ] ]
18+
19+ const invalidLimitOptions = [
20+ { option : 'fieldNameSize' , value : - 100 } ,
21+ { option : 'fieldSize' , value : 0.5 } ,
22+ { option : 'fields' , value : '10' } ,
23+ { option : 'files' , value : 'foo' } ,
24+ { option : 'fileSize' , value : 1048.15 } ,
25+ { option : 'parts' , value : '0' } ,
26+ { option : 'headersPairs' , value : - 10.55 }
27+ ]
28+
29+ invalidLimitOptions . forEach ( ( { option, value } ) => {
30+ it ( `should throw an invalid limit option error for ${ option } with value ${ value } ` , ( ) => {
31+ assert . throws (
32+ ( ) => multer ( { limits : { [ option ] : value } } ) ,
33+ ( err ) => {
34+ return (
35+ err instanceof multer . MulterError &&
36+ err . name === 'MulterError' &&
37+ err . code === 'LIMIT_OPTION_ERROR' &&
38+ err . field === `option "${ option } " value: ${ value } ` &&
39+ err . message === `Limit option must be an integer: option "${ option } " value: ${ value } `
40+ )
41+ } ,
42+ `Expected multer to reject ${ option } value for ${ value } `
43+ )
44+ } )
45+ } )
46+
47+ it ( 'should throw argument type error if limits is not a plain object' , function ( ) {
48+ invalidPlainObj . forEach ( option => {
49+ assert . throws (
50+ ( ) => multer ( { limits : option } ) ,
51+ ( err ) => {
52+ return err instanceof TypeError && err . message === 'Expected limits to be a plain object'
53+ } ,
54+ 'Expected multer to throw TypeError for non-object limits'
55+ )
56+ } )
57+ } )
58+
59+ it ( 'should throw type error if options is not a plain object' , function ( ) {
60+ invalidPlainObj . forEach ( option => {
61+ assert . throws (
62+ ( ) => multer ( option ) ,
63+ ( err ) => {
64+ return err instanceof TypeError && err . message === 'Expected object for argument options'
65+ } ,
66+ 'Expected multer to throw TypeError for non plain object options'
67+ )
68+ } )
69+ } )
70+
1771 it ( 'should be an instance of both `Error` and `MulterError` classes in case of the Multer\'s error' , function ( done ) {
1872 var form = new FormData ( )
1973 var storage = multer . diskStorage ( { destination : os . tmpdir ( ) } )
0 commit comments