@@ -71,6 +71,21 @@ describe('normalizeOptions(options, defaultType)', () => {
7171 assert . strictEqual ( result . limit , 100 * 1024 ) // 100kb in bytes
7272 } )
7373
74+ it ( 'should return the default limit if limit is undefined' , ( ) => {
75+ const result = normalizeOptions ( { limit : undefined } , 'application/json' )
76+ assert . strictEqual ( result . limit , 100 * 1024 ) // 100kb in bytes
77+ } )
78+
79+ it ( 'should return the default limit if limit is null' , ( ) => {
80+ const result = normalizeOptions ( { limit : null } , 'application/json' )
81+ assert . strictEqual ( result . limit , 100 * 1024 ) // 100kb in bytes
82+ } )
83+
84+ it ( 'should accept zero as valid limit' , ( ) => {
85+ const result = normalizeOptions ( { limit : 0 } , 'application/json' )
86+ assert . strictEqual ( result . limit , 0 )
87+ } )
88+
7489 it ( 'should accept a number limit' , ( ) => {
7590 const result = normalizeOptions ( { limit : 1234 } , 'application/json' )
7691 assert . strictEqual ( result . limit , 1234 )
@@ -81,9 +96,39 @@ describe('normalizeOptions(options, defaultType)', () => {
8196 assert . strictEqual ( result . limit , 200 * 1024 ) // 200kb in bytes
8297 } )
8398
84- it ( 'should return null for an invalid limit' , ( ) => {
85- const result = normalizeOptions ( { limit : 'invalid' } , 'application/json' )
86- assert . strictEqual ( result . limit , null )
99+ it ( 'should parse a string limit without a unit' , ( ) => {
100+ const result = normalizeOptions ( { limit : '200' } , 'application/json' )
101+ assert . strictEqual ( result . limit , 200 ) // 200 bytes
102+ } )
103+
104+ it ( 'should throw an error for an invalid string limit' , ( ) => {
105+ assert . throws ( ( ) => {
106+ normalizeOptions ( { limit : 'invalid' } , 'application/json' )
107+ } , / o p t i o n l i m i t " i n v a l i d " i s i n v a l i d / )
108+ assert . throws ( ( ) => {
109+ normalizeOptions ( { limit : '' } , 'application/json' )
110+ } , / o p t i o n l i m i t " " i s i n v a l i d / )
111+ } )
112+
113+ it ( 'should throw an error for a NaN limit' , ( ) => {
114+ assert . throws ( ( ) => {
115+ normalizeOptions ( { limit : NaN } , 'application/json' )
116+ } , / o p t i o n l i m i t " N a N " i s i n v a l i d / )
117+ } )
118+
119+ it ( 'should throw an error for a boolean limit' , ( ) => {
120+ assert . throws ( ( ) => {
121+ normalizeOptions ( { limit : true } , 'application/json' )
122+ } , / o p t i o n l i m i t " t r u e " i s i n v a l i d / )
123+ assert . throws ( ( ) => {
124+ normalizeOptions ( { limit : false } , 'application/json' )
125+ } , / o p t i o n l i m i t " f a l s e " i s i n v a l i d / )
126+ } )
127+
128+ it ( 'should throw an error for an object limit' , ( ) => {
129+ assert . throws ( ( ) => {
130+ normalizeOptions ( { limit : { foo : 'bar' } } , 'application/json' )
131+ } , / o p t i o n l i m i t " \[ o b j e c t O b j e c t \] " i s i n v a l i d / )
87132 } )
88133 } )
89134
0 commit comments