@@ -64,6 +64,41 @@ describe('req', function(){
6464 . expect ( / T y p e E r r o r : s i z e m u s t b e a n o n - n e g a t i v e i n t e g e r t o r e q \. r a n g e / ) ;
6565 } ) ;
6666
67+ it ( 'should throw TypeError for various invalid size types' , function ( ) {
68+ var app = express ( ) ;
69+ var testCases = [
70+ { value : 'string' , label : 'string' } ,
71+ { value : { } , label : 'object' } ,
72+ { value : [ ] , label : 'array' } ,
73+ { value : null , label : 'null' } ,
74+ { value : undefined , label : 'undefined' } ,
75+ { value : 1.5 , label : 'float' } ,
76+ { value : NaN , label : 'NaN' } ,
77+ { value : Infinity , label : 'Infinity' }
78+ ] ;
79+
80+ app . use ( function ( req , res ) {
81+ var type = req . query . type ;
82+ var value = testCases . find ( c => c . label === type ) . value ;
83+
84+ try {
85+ req . range ( value ) ;
86+ res . send ( 'no error' ) ;
87+ } catch ( err ) {
88+ res . status ( 500 ) . send ( err . name + ': ' + err . message ) ;
89+ }
90+ } ) ;
91+
92+ // Run all tests in sequence
93+ return Promise . all ( testCases . map ( function ( testCase ) {
94+ return request ( app )
95+ . get ( '/?type=' + testCase . label )
96+ . set ( 'Range' , 'bytes=0-10' )
97+ . expect ( 500 )
98+ . expect ( / T y p e E r r o r : s i z e m u s t b e a n o n - n e g a t i v e i n t e g e r t o r e q \. r a n g e / ) ;
99+ } ) ) ;
100+ } ) ;
101+
67102 it ( 'should have a .type' , function ( done ) {
68103 var app = express ( )
69104
0 commit comments