@@ -1233,7 +1233,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1233
1233
* Creates a new backend definition.
1234
1234
*
1235
1235
* @param {string } method HTTP method.
1236
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1236
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1237
1237
* and returns true if the url matches the current definition.
1238
1238
* @param {(string|RegExp|function(string))= } data HTTP request body or function that receives
1239
1239
* data string and returns true if the data is as expected.
@@ -1252,6 +1252,9 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1252
1252
* `requestHandler` object for possible overrides.
1253
1253
*/
1254
1254
$httpBackend . when = function ( method , url , data , headers ) {
1255
+
1256
+ assertArgDefined ( arguments , 1 , 'url' ) ;
1257
+
1255
1258
var definition = new MockHttpExpectation ( method , url , data , headers ) ,
1256
1259
chain = {
1257
1260
respond : function ( status , data , headers , statusText ) {
@@ -1279,7 +1282,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1279
1282
* @description
1280
1283
* Creates a new backend definition for GET requests. For more info see `when()`.
1281
1284
*
1282
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1285
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1283
1286
* and returns true if the url matches the current definition.
1284
1287
* @param {(Object|function(Object))= } headers HTTP headers.
1285
1288
* @returns {requestHandler } Returns an object with `respond` method that controls how a matched
@@ -1293,7 +1296,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1293
1296
* @description
1294
1297
* Creates a new backend definition for HEAD requests. For more info see `when()`.
1295
1298
*
1296
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1299
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1297
1300
* and returns true if the url matches the current definition.
1298
1301
* @param {(Object|function(Object))= } headers HTTP headers.
1299
1302
* @returns {requestHandler } Returns an object with `respond` method that controls how a matched
@@ -1307,7 +1310,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1307
1310
* @description
1308
1311
* Creates a new backend definition for DELETE requests. For more info see `when()`.
1309
1312
*
1310
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1313
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1311
1314
* and returns true if the url matches the current definition.
1312
1315
* @param {(Object|function(Object))= } headers HTTP headers.
1313
1316
* @returns {requestHandler } Returns an object with `respond` method that controls how a matched
@@ -1321,7 +1324,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1321
1324
* @description
1322
1325
* Creates a new backend definition for POST requests. For more info see `when()`.
1323
1326
*
1324
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1327
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1325
1328
* and returns true if the url matches the current definition.
1326
1329
* @param {(string|RegExp|function(string))= } data HTTP request body or function that receives
1327
1330
* data string and returns true if the data is as expected.
@@ -1337,7 +1340,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1337
1340
* @description
1338
1341
* Creates a new backend definition for PUT requests. For more info see `when()`.
1339
1342
*
1340
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1343
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1341
1344
* and returns true if the url matches the current definition.
1342
1345
* @param {(string|RegExp|function(string))= } data HTTP request body or function that receives
1343
1346
* data string and returns true if the data is as expected.
@@ -1353,7 +1356,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1353
1356
* @description
1354
1357
* Creates a new backend definition for JSONP requests. For more info see `when()`.
1355
1358
*
1356
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1359
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1357
1360
* and returns true if the url matches the current definition.
1358
1361
* @returns {requestHandler } Returns an object with `respond` method that controls how a matched
1359
1362
* request is handled. You can save this object for later use and invoke `respond` again in
@@ -1369,7 +1372,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1369
1372
* Creates a new request expectation.
1370
1373
*
1371
1374
* @param {string } method HTTP method.
1372
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1375
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1373
1376
* and returns true if the url matches the current definition.
1374
1377
* @param {(string|RegExp|function(string)|Object)= } data HTTP request body or function that
1375
1378
* receives data string and returns true if the data is as expected, or Object if request body
@@ -1389,6 +1392,9 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1389
1392
* `requestHandler` object for possible overrides.
1390
1393
*/
1391
1394
$httpBackend . expect = function ( method , url , data , headers ) {
1395
+
1396
+ assertArgDefined ( arguments , 1 , 'url' ) ;
1397
+
1392
1398
var expectation = new MockHttpExpectation ( method , url , data , headers ) ,
1393
1399
chain = {
1394
1400
respond : function ( status , data , headers , statusText ) {
@@ -1408,7 +1414,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1408
1414
* @description
1409
1415
* Creates a new request expectation for GET requests. For more info see `expect()`.
1410
1416
*
1411
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1417
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1412
1418
* and returns true if the url matches the current definition.
1413
1419
* @param {Object= } headers HTTP headers.
1414
1420
* @returns {requestHandler } Returns an object with `respond` method that controls how a matched
@@ -1422,7 +1428,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1422
1428
* @description
1423
1429
* Creates a new request expectation for HEAD requests. For more info see `expect()`.
1424
1430
*
1425
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1431
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1426
1432
* and returns true if the url matches the current definition.
1427
1433
* @param {Object= } headers HTTP headers.
1428
1434
* @returns {requestHandler } Returns an object with `respond` method that controls how a matched
@@ -1436,7 +1442,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1436
1442
* @description
1437
1443
* Creates a new request expectation for DELETE requests. For more info see `expect()`.
1438
1444
*
1439
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1445
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1440
1446
* and returns true if the url matches the current definition.
1441
1447
* @param {Object= } headers HTTP headers.
1442
1448
* @returns {requestHandler } Returns an object with `respond` method that controls how a matched
@@ -1450,7 +1456,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1450
1456
* @description
1451
1457
* Creates a new request expectation for POST requests. For more info see `expect()`.
1452
1458
*
1453
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1459
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1454
1460
* and returns true if the url matches the current definition.
1455
1461
* @param {(string|RegExp|function(string)|Object)= } data HTTP request body or function that
1456
1462
* receives data string and returns true if the data is as expected, or Object if request body
@@ -1467,7 +1473,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1467
1473
* @description
1468
1474
* Creates a new request expectation for PUT requests. For more info see `expect()`.
1469
1475
*
1470
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1476
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1471
1477
* and returns true if the url matches the current definition.
1472
1478
* @param {(string|RegExp|function(string)|Object)= } data HTTP request body or function that
1473
1479
* receives data string and returns true if the data is as expected, or Object if request body
@@ -1484,7 +1490,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1484
1490
* @description
1485
1491
* Creates a new request expectation for PATCH requests. For more info see `expect()`.
1486
1492
*
1487
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1493
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1488
1494
* and returns true if the url matches the current definition.
1489
1495
* @param {(string|RegExp|function(string)|Object)= } data HTTP request body or function that
1490
1496
* receives data string and returns true if the data is as expected, or Object if request body
@@ -1501,7 +1507,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1501
1507
* @description
1502
1508
* Creates a new request expectation for JSONP requests. For more info see `expect()`.
1503
1509
*
1504
- * @param {string|RegExp|function(string) } url HTTP url or function that receives an url
1510
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives an url
1505
1511
* and returns true if the url matches the current definition.
1506
1512
* @returns {requestHandler } Returns an object with `respond` method that controls how a matched
1507
1513
* request is handled. You can save this object for later use and invoke `respond` again in
@@ -1595,22 +1601,38 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1595
1601
1596
1602
return $httpBackend ;
1597
1603
1598
-
1599
1604
function createShortMethods ( prefix ) {
1600
1605
angular . forEach ( [ 'GET' , 'DELETE' , 'JSONP' , 'HEAD' ] , function ( method ) {
1601
- $httpBackend [ prefix + method ] = function ( url , headers ) {
1602
- return $httpBackend [ prefix ] ( method , url , undefined , headers ) ;
1603
- } ;
1606
+ $httpBackend [ prefix + method ] = function ( url , headers ) {
1607
+ assertArgDefined ( arguments , 0 , 'url' ) ;
1608
+
1609
+ // Change url to `null` if `undefined` to stop it throwing an exception further down
1610
+ if ( angular . isUndefined ( url ) ) url = null ;
1611
+
1612
+ return $httpBackend [ prefix ] ( method , url , undefined , headers ) ;
1613
+ } ;
1604
1614
} ) ;
1605
1615
1606
1616
angular . forEach ( [ 'PUT' , 'POST' , 'PATCH' ] , function ( method ) {
1607
1617
$httpBackend [ prefix + method ] = function ( url , data , headers ) {
1618
+ assertArgDefined ( arguments , 0 , 'url' ) ;
1619
+
1620
+ // Change url to `null` if `undefined` to stop it throwing an exception further down
1621
+ if ( angular . isUndefined ( url ) ) url = null ;
1622
+
1608
1623
return $httpBackend [ prefix ] ( method , url , data , headers ) ;
1609
1624
} ;
1610
1625
} ) ;
1611
1626
}
1612
1627
}
1613
1628
1629
+ function assertArgDefined ( args , index , name ) {
1630
+ if ( args . length > index && angular . isUndefined ( args [ index ] ) ) {
1631
+ throw new Error ( "Undefined argument `" + name + "`; the argument is provided but not defined" ) ;
1632
+ }
1633
+ }
1634
+
1635
+
1614
1636
function MockHttpExpectation ( method , url , data , headers ) {
1615
1637
1616
1638
this . data = data ;
@@ -1969,7 +1991,7 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
1969
1991
* Creates a new backend definition.
1970
1992
*
1971
1993
* @param {string } method HTTP method.
1972
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1994
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1973
1995
* and returns true if the url matches the current definition.
1974
1996
* @param {(string|RegExp)= } data HTTP request body.
1975
1997
* @param {(Object|function(Object))= } headers HTTP headers or function that receives http header
@@ -1997,7 +2019,7 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
1997
2019
* @description
1998
2020
* Creates a new backend definition for GET requests. For more info see `when()`.
1999
2021
*
2000
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
2022
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
2001
2023
* and returns true if the url matches the current definition.
2002
2024
* @param {(Object|function(Object))= } headers HTTP headers.
2003
2025
* @returns {requestHandler } Returns an object with `respond` and `passThrough` methods that
@@ -2012,7 +2034,7 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
2012
2034
* @description
2013
2035
* Creates a new backend definition for HEAD requests. For more info see `when()`.
2014
2036
*
2015
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
2037
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
2016
2038
* and returns true if the url matches the current definition.
2017
2039
* @param {(Object|function(Object))= } headers HTTP headers.
2018
2040
* @returns {requestHandler } Returns an object with `respond` and `passThrough` methods that
@@ -2027,7 +2049,7 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
2027
2049
* @description
2028
2050
* Creates a new backend definition for DELETE requests. For more info see `when()`.
2029
2051
*
2030
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
2052
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
2031
2053
* and returns true if the url matches the current definition.
2032
2054
* @param {(Object|function(Object))= } headers HTTP headers.
2033
2055
* @returns {requestHandler } Returns an object with `respond` and `passThrough` methods that
@@ -2042,7 +2064,7 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
2042
2064
* @description
2043
2065
* Creates a new backend definition for POST requests. For more info see `when()`.
2044
2066
*
2045
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
2067
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
2046
2068
* and returns true if the url matches the current definition.
2047
2069
* @param {(string|RegExp)= } data HTTP request body.
2048
2070
* @param {(Object|function(Object))= } headers HTTP headers.
@@ -2058,7 +2080,7 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
2058
2080
* @description
2059
2081
* Creates a new backend definition for PUT requests. For more info see `when()`.
2060
2082
*
2061
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
2083
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
2062
2084
* and returns true if the url matches the current definition.
2063
2085
* @param {(string|RegExp)= } data HTTP request body.
2064
2086
* @param {(Object|function(Object))= } headers HTTP headers.
@@ -2074,7 +2096,7 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
2074
2096
* @description
2075
2097
* Creates a new backend definition for PATCH requests. For more info see `when()`.
2076
2098
*
2077
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
2099
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
2078
2100
* and returns true if the url matches the current definition.
2079
2101
* @param {(string|RegExp)= } data HTTP request body.
2080
2102
* @param {(Object|function(Object))= } headers HTTP headers.
@@ -2090,7 +2112,7 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
2090
2112
* @description
2091
2113
* Creates a new backend definition for JSONP requests. For more info see `when()`.
2092
2114
*
2093
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
2115
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
2094
2116
* and returns true if the url matches the current definition.
2095
2117
* @returns {requestHandler } Returns an object with `respond` and `passThrough` methods that
2096
2118
* control how a matched request is handled. You can save this object for later use and invoke
0 commit comments