@@ -1423,7 +1423,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1423
1423
* Creates a new backend definition.
1424
1424
*
1425
1425
* @param {string } method HTTP method.
1426
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1426
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1427
1427
* and returns true if the url matches the current definition.
1428
1428
* @param {(string|RegExp|function(string))= } data HTTP request body or function that receives
1429
1429
* data string and returns true if the data is as expected.
@@ -1445,6 +1445,9 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1445
1445
* the `requestHandler` object for possible overrides.
1446
1446
*/
1447
1447
$httpBackend . when = function ( method , url , data , headers , keys ) {
1448
+
1449
+ assertArgDefined ( arguments , 1 , 'url' ) ;
1450
+
1448
1451
var definition = new MockHttpExpectation ( method , url , data , headers , keys ) ,
1449
1452
chain = {
1450
1453
respond : function ( status , data , headers , statusText ) {
@@ -1472,7 +1475,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1472
1475
* @description
1473
1476
* Creates a new backend definition for GET requests. For more info see `when()`.
1474
1477
*
1475
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1478
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1476
1479
* and returns true if the url matches the current definition.
1477
1480
* @param {(Object|function(Object))= } headers HTTP headers.
1478
1481
* @param {(Array)= } keys Array of keys to assign to regex matches in request url described above.
@@ -1487,7 +1490,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1487
1490
* @description
1488
1491
* Creates a new backend definition for HEAD requests. For more info see `when()`.
1489
1492
*
1490
- * @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
1491
1494
* and returns true if the url matches the current definition.
1492
1495
* @param {(Object|function(Object))= } headers HTTP headers.
1493
1496
* @param {(Array)= } keys Array of keys to assign to regex matches in request url described above.
@@ -1502,7 +1505,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1502
1505
* @description
1503
1506
* Creates a new backend definition for DELETE requests. For more info see `when()`.
1504
1507
*
1505
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1508
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1506
1509
* and returns true if the url matches the current definition.
1507
1510
* @param {(Object|function(Object))= } headers HTTP headers.
1508
1511
* @param {(Array)= } keys Array of keys to assign to regex matches in request url described above.
@@ -1517,7 +1520,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1517
1520
* @description
1518
1521
* Creates a new backend definition for POST requests. For more info see `when()`.
1519
1522
*
1520
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1523
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1521
1524
* and returns true if the url matches the current definition.
1522
1525
* @param {(string|RegExp|function(string))= } data HTTP request body or function that receives
1523
1526
* data string and returns true if the data is as expected.
@@ -1534,7 +1537,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1534
1537
* @description
1535
1538
* Creates a new backend definition for PUT requests. For more info see `when()`.
1536
1539
*
1537
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1540
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1538
1541
* and returns true if the url matches the current definition.
1539
1542
* @param {(string|RegExp|function(string))= } data HTTP request body or function that receives
1540
1543
* data string and returns true if the data is as expected.
@@ -1551,7 +1554,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1551
1554
* @description
1552
1555
* Creates a new backend definition for JSONP requests. For more info see `when()`.
1553
1556
*
1554
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1557
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1555
1558
* and returns true if the url matches the current definition.
1556
1559
* @param {(Array)= } keys Array of keys to assign to regex matches in request url described above.
1557
1560
* @returns {requestHandler } Returns an object with `respond` method that controls how a matched
@@ -1614,7 +1617,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1614
1617
* Creates a new request expectation.
1615
1618
*
1616
1619
* @param {string } method HTTP method.
1617
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1620
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1618
1621
* and returns true if the url matches the current definition.
1619
1622
* @param {(string|RegExp|function(string)|Object)= } data HTTP request body or function that
1620
1623
* receives data string and returns true if the data is as expected, or Object if request body
@@ -1637,6 +1640,9 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1637
1640
* the `requestHandler` object for possible overrides.
1638
1641
*/
1639
1642
$httpBackend . expect = function ( method , url , data , headers , keys ) {
1643
+
1644
+ assertArgDefined ( arguments , 1 , 'url' ) ;
1645
+
1640
1646
var expectation = new MockHttpExpectation ( method , url , data , headers , keys ) ,
1641
1647
chain = {
1642
1648
respond : function ( status , data , headers , statusText ) {
@@ -1655,7 +1661,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1655
1661
* @description
1656
1662
* Creates a new request expectation for GET requests. For more info see `expect()`.
1657
1663
*
1658
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1664
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1659
1665
* and returns true if the url matches the current definition.
1660
1666
* @param {Object= } headers HTTP headers.
1661
1667
* @param {(Array)= } keys Array of keys to assign to regex matches in request url described above.
@@ -1670,7 +1676,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1670
1676
* @description
1671
1677
* Creates a new request expectation for HEAD requests. For more info see `expect()`.
1672
1678
*
1673
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1679
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1674
1680
* and returns true if the url matches the current definition.
1675
1681
* @param {Object= } headers HTTP headers.
1676
1682
* @param {(Array)= } keys Array of keys to assign to regex matches in request url described above.
@@ -1685,7 +1691,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1685
1691
* @description
1686
1692
* Creates a new request expectation for DELETE requests. For more info see `expect()`.
1687
1693
*
1688
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1694
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1689
1695
* and returns true if the url matches the current definition.
1690
1696
* @param {Object= } headers HTTP headers.
1691
1697
* @param {(Array)= } keys Array of keys to assign to regex matches in request url described above.
@@ -1700,7 +1706,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1700
1706
* @description
1701
1707
* Creates a new request expectation for POST requests. For more info see `expect()`.
1702
1708
*
1703
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1709
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1704
1710
* and returns true if the url matches the current definition.
1705
1711
* @param {(string|RegExp|function(string)|Object)= } data HTTP request body or function that
1706
1712
* receives data string and returns true if the data is as expected, or Object if request body
@@ -1718,7 +1724,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1718
1724
* @description
1719
1725
* Creates a new request expectation for PUT requests. For more info see `expect()`.
1720
1726
*
1721
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1727
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1722
1728
* and returns true if the url matches the current definition.
1723
1729
* @param {(string|RegExp|function(string)|Object)= } data HTTP request body or function that
1724
1730
* receives data string and returns true if the data is as expected, or Object if request body
@@ -1736,7 +1742,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1736
1742
* @description
1737
1743
* Creates a new request expectation for PATCH requests. For more info see `expect()`.
1738
1744
*
1739
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
1745
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
1740
1746
* and returns true if the url matches the current definition.
1741
1747
* @param {(string|RegExp|function(string)|Object)= } data HTTP request body or function that
1742
1748
* receives data string and returns true if the data is as expected, or Object if request body
@@ -1754,7 +1760,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1754
1760
* @description
1755
1761
* Creates a new request expectation for JSONP requests. For more info see `expect()`.
1756
1762
*
1757
- * @param {string|RegExp|function(string) } url HTTP url or function that receives an url
1763
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives an url
1758
1764
* and returns true if the url matches the current definition.
1759
1765
* @param {(Array)= } keys Array of keys to assign to regex matches in request url described above.
1760
1766
* @returns {requestHandler } Returns an object with `respond` method that controls how a matched
@@ -1870,18 +1876,35 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1870
1876
function createShortMethods ( prefix ) {
1871
1877
angular . forEach ( [ 'GET' , 'DELETE' , 'JSONP' , 'HEAD' ] , function ( method ) {
1872
1878
$httpBackend [ prefix + method ] = function ( url , headers , keys ) {
1879
+ assertArgDefined ( arguments , 0 , 'url' ) ;
1880
+
1881
+ // Change url to `null` if `undefined` to stop it throwing an exception further down
1882
+ if ( angular . isUndefined ( url ) ) url = null ;
1883
+
1873
1884
return $httpBackend [ prefix ] ( method , url , undefined , headers , keys ) ;
1874
1885
} ;
1875
1886
} ) ;
1876
1887
1877
1888
angular . forEach ( [ 'PUT' , 'POST' , 'PATCH' ] , function ( method ) {
1878
1889
$httpBackend [ prefix + method ] = function ( url , data , headers , keys ) {
1890
+ assertArgDefined ( arguments , 0 , 'url' ) ;
1891
+
1892
+ // Change url to `null` if `undefined` to stop it throwing an exception further down
1893
+ if ( angular . isUndefined ( url ) ) url = null ;
1894
+
1879
1895
return $httpBackend [ prefix ] ( method , url , data , headers , keys ) ;
1880
1896
} ;
1881
1897
} ) ;
1882
1898
}
1883
1899
}
1884
1900
1901
+ function assertArgDefined ( args , index , name ) {
1902
+ if ( args . length > index && angular . isUndefined ( args [ index ] ) ) {
1903
+ throw new Error ( "Undefined argument `" + name + "`; the argument is provided but not defined" ) ;
1904
+ }
1905
+ }
1906
+
1907
+
1885
1908
function MockHttpExpectation ( method , url , data , headers , keys ) {
1886
1909
1887
1910
function getUrlParams ( u ) {
@@ -2462,7 +2485,7 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
2462
2485
* Creates a new backend definition.
2463
2486
*
2464
2487
* @param {string } method HTTP method.
2465
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
2488
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
2466
2489
* and returns true if the url matches the current definition.
2467
2490
* @param {(string|RegExp)= } data HTTP request body.
2468
2491
* @param {(Object|function(Object))= } headers HTTP headers or function that receives http header
@@ -2494,7 +2517,7 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
2494
2517
* @description
2495
2518
* Creates a new backend definition for GET requests. For more info see `when()`.
2496
2519
*
2497
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
2520
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
2498
2521
* and returns true if the url matches the current definition.
2499
2522
* @param {(Object|function(Object))= } headers HTTP headers.
2500
2523
* @param {(Array)= } keys Array of keys to assign to regex matches in request url described on
@@ -2511,7 +2534,7 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
2511
2534
* @description
2512
2535
* Creates a new backend definition for HEAD requests. For more info see `when()`.
2513
2536
*
2514
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
2537
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
2515
2538
* and returns true if the url matches the current definition.
2516
2539
* @param {(Object|function(Object))= } headers HTTP headers.
2517
2540
* @param {(Array)= } keys Array of keys to assign to regex matches in request url described on
@@ -2528,7 +2551,7 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
2528
2551
* @description
2529
2552
* Creates a new backend definition for DELETE requests. For more info see `when()`.
2530
2553
*
2531
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
2554
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
2532
2555
* and returns true if the url matches the current definition.
2533
2556
* @param {(Object|function(Object))= } headers HTTP headers.
2534
2557
* @param {(Array)= } keys Array of keys to assign to regex matches in request url described on
@@ -2545,7 +2568,7 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
2545
2568
* @description
2546
2569
* Creates a new backend definition for POST requests. For more info see `when()`.
2547
2570
*
2548
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
2571
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
2549
2572
* and returns true if the url matches the current definition.
2550
2573
* @param {(string|RegExp)= } data HTTP request body.
2551
2574
* @param {(Object|function(Object))= } headers HTTP headers.
@@ -2563,7 +2586,7 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
2563
2586
* @description
2564
2587
* Creates a new backend definition for PUT requests. For more info see `when()`.
2565
2588
*
2566
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
2589
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
2567
2590
* and returns true if the url matches the current definition.
2568
2591
* @param {(string|RegExp)= } data HTTP request body.
2569
2592
* @param {(Object|function(Object))= } headers HTTP headers.
@@ -2581,7 +2604,7 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
2581
2604
* @description
2582
2605
* Creates a new backend definition for PATCH requests. For more info see `when()`.
2583
2606
*
2584
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
2607
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
2585
2608
* and returns true if the url matches the current definition.
2586
2609
* @param {(string|RegExp)= } data HTTP request body.
2587
2610
* @param {(Object|function(Object))= } headers HTTP headers.
@@ -2599,7 +2622,7 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
2599
2622
* @description
2600
2623
* Creates a new backend definition for JSONP requests. For more info see `when()`.
2601
2624
*
2602
- * @param {string|RegExp|function(string) } url HTTP url or function that receives a url
2625
+ * @param {string|RegExp|function(string)= } url HTTP url or function that receives a url
2603
2626
* and returns true if the url matches the current definition.
2604
2627
* @param {(Array)= } keys Array of keys to assign to regex matches in request url described on
2605
2628
* {@link ngMock.$httpBackend $httpBackend mock}.
0 commit comments