@@ -1316,7 +1316,7 @@ describe("resource", function() {
1316
1316
} ) ;
1317
1317
1318
1318
describe ( 'resource' , function ( ) {
1319
- var $httpBackend , $resource ;
1319
+ var $httpBackend , $resource , $q ;
1320
1320
1321
1321
beforeEach ( module ( function ( $exceptionHandlerProvider ) {
1322
1322
$exceptionHandlerProvider . mode ( 'log' ) ;
@@ -1327,6 +1327,7 @@ describe('resource', function() {
1327
1327
beforeEach ( inject ( function ( $injector ) {
1328
1328
$httpBackend = $injector . get ( '$httpBackend' ) ;
1329
1329
$resource = $injector . get ( '$resource' ) ;
1330
+ $q = $injector . get ( '$q' ) ;
1330
1331
} ) ) ;
1331
1332
1332
1333
@@ -1364,5 +1365,34 @@ describe('resource', function() {
1364
1365
) ;
1365
1366
} ) ;
1366
1367
1368
+ it ( 'should cancel the request if timeout promise is resolved' , function ( ) {
1369
+ var canceler = $q . defer ( ) ;
1370
+
1371
+ $httpBackend . when ( 'GET' , '/CreditCard' ) . respond ( { data : '123' } ) ;
1372
+
1373
+ var CreditCard = $resource ( '/CreditCard' , { } , {
1374
+ query : {
1375
+ method : 'GET' ,
1376
+ timeout : canceler . promise
1377
+ }
1378
+ } ) ;
1379
+
1380
+ CreditCard . query ( ) ;
1381
+
1382
+ canceler . resolve ( ) ;
1383
+ expect ( $httpBackend . flush ) . toThrow ( new Error ( "No pending request to flush !" ) ) ;
1384
+
1385
+ canceler = $q . defer ( ) ;
1386
+ CreditCard = $resource ( '/CreditCard' , { } , {
1387
+ query : {
1388
+ method : 'GET' ,
1389
+ timeout : canceler . promise
1390
+ }
1391
+ } ) ;
1392
+
1393
+ CreditCard . query ( ) ;
1394
+ expect ( $httpBackend . flush ) . not . toThrow ( ) ;
1395
+ } ) ;
1396
+
1367
1397
1368
1398
} ) ;
0 commit comments