@@ -29,6 +29,64 @@ describe('supports http with nodejs', function () {
2929 }
3030 } ) ;
3131
32+ it ( 'should throw an error if the timeout property is not parsable as a number' , function ( done ) {
33+
34+ server = http . createServer ( function ( req , res ) {
35+ setTimeout ( function ( ) {
36+ res . end ( ) ;
37+ } , 1000 ) ;
38+ } ) . listen ( 4444 , function ( ) {
39+ var success = false , failure = false ;
40+ var error ;
41+
42+ axios . get ( 'http://localhost:4444/' , {
43+ timeout : { strangeTimeout : 250 }
44+ } ) . then ( function ( res ) {
45+ success = true ;
46+ } ) . catch ( function ( err ) {
47+ error = err ;
48+ failure = true ;
49+ } ) ;
50+
51+ setTimeout ( function ( ) {
52+ assert . equal ( success , false , 'request should not succeed' ) ;
53+ assert . equal ( failure , true , 'request should fail' ) ;
54+ assert . equal ( error . code , 'ERR_PARSE_TIMEOUT' ) ;
55+ assert . equal ( error . message , 'error trying to parse `config.timeout` to int' ) ;
56+ done ( ) ;
57+ } , 300 ) ;
58+ } ) ;
59+ } ) ;
60+
61+ it ( 'should parse the timeout property' , function ( done ) {
62+
63+ server = http . createServer ( function ( req , res ) {
64+ setTimeout ( function ( ) {
65+ res . end ( ) ;
66+ } , 1000 ) ;
67+ } ) . listen ( 4444 , function ( ) {
68+ var success = false , failure = false ;
69+ var error ;
70+
71+ axios . get ( 'http://localhost:4444/' , {
72+ timeout : '250'
73+ } ) . then ( function ( res ) {
74+ success = true ;
75+ } ) . catch ( function ( err ) {
76+ error = err ;
77+ failure = true ;
78+ } ) ;
79+
80+ setTimeout ( function ( ) {
81+ assert . equal ( success , false , 'request should not succeed' ) ;
82+ assert . equal ( failure , true , 'request should fail' ) ;
83+ assert . equal ( error . code , 'ECONNABORTED' ) ;
84+ assert . equal ( error . message , 'timeout of 250ms exceeded' ) ;
85+ done ( ) ;
86+ } , 300 ) ;
87+ } ) ;
88+ } ) ;
89+
3290 it ( 'should respect the timeout property' , function ( done ) {
3391
3492 server = http . createServer ( function ( req , res ) {
0 commit comments