@@ -1308,7 +1308,7 @@ describe("resource", function() {
1308
1308
} ) ;
1309
1309
1310
1310
describe ( 'resource' , function ( ) {
1311
- var $httpBackend , $resource ;
1311
+ var $httpBackend , $resource , $q ;
1312
1312
1313
1313
beforeEach ( module ( function ( $exceptionHandlerProvider ) {
1314
1314
$exceptionHandlerProvider . mode ( 'log' ) ;
@@ -1319,6 +1319,7 @@ describe('resource', function() {
1319
1319
beforeEach ( inject ( function ( $injector ) {
1320
1320
$httpBackend = $injector . get ( '$httpBackend' ) ;
1321
1321
$resource = $injector . get ( '$resource' ) ;
1322
+ $q = $injector . get ( '$q' ) ;
1322
1323
} ) ) ;
1323
1324
1324
1325
@@ -1356,5 +1357,36 @@ describe('resource', function() {
1356
1357
) ;
1357
1358
} ) ;
1358
1359
1360
+ it ( 'If timeout promise is resolved, cancel the request' , function ( ) {
1361
+ var canceler = $q . defer ( ) ;
1362
+
1363
+ $httpBackend . when ( 'GET' , '/CreditCard' ) . respond ( { data : '123' } ) ;
1364
+
1365
+ var CreditCard = $resource ( '/CreditCard' , { } , {
1366
+ query : {
1367
+ method : 'GET' ,
1368
+ timeout : canceler . promise
1369
+ }
1370
+ } ) ;
1371
+
1372
+ CreditCard . query ( ) ;
1373
+
1374
+ canceler . resolve ( ) ;
1375
+ expect ( function ( ) { $httpBackend . flush ( ) ; } ) . toThrow ( new Error ( "No pending request to flush !" ) ) ;
1376
+
1377
+ canceler = $q . defer ( ) ;
1378
+ CreditCard = $resource ( '/CreditCard' , { } , {
1379
+ query : {
1380
+ method : 'GET' ,
1381
+ timeout : canceler . promise
1382
+ }
1383
+ } ) ;
1384
+
1385
+ CreditCard . query ( ) ;
1386
+ expect ( function ( ) { $httpBackend . flush ( ) ; } ) . not . toThrow ( new Error ( "No pending request to flush !" ) ) ;
1387
+
1388
+
1389
+ } ) ;
1390
+
1359
1391
1360
1392
} ) ;
0 commit comments