1
1
'use strict' ;
2
2
3
+ /* global routeToRegExp: false */
4
+
3
5
/**
4
6
* @ngdoc object
5
7
* @name angular.mock
@@ -1481,8 +1483,9 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1481
1483
* ```
1482
1484
* – The respond method takes a set of static data to be returned or a function that can
1483
1485
* return an array containing response status (number), response data (Array|Object|string),
1484
- * response headers (Object), and the text for the status (string). The respond method returns
1485
- * the `requestHandler` object for possible overrides.
1486
+ * response headers (Object), HTTP status text (string), and XMLHttpRequest status (string:
1487
+ * `complete`, `error`, `timeout` or `abort`). The respond method returns the `requestHandler`
1488
+ * object for possible overrides.
1486
1489
*/
1487
1490
$httpBackend . when = function ( method , url , data , headers , keys ) {
1488
1491
@@ -1663,40 +1666,10 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1663
1666
* See {@link ngMock.$httpBackend#when `when`} for more info.
1664
1667
*/
1665
1668
$httpBackend . whenRoute = function ( method , url ) {
1666
- var pathObj = parseRoute ( url ) ;
1669
+ var pathObj = routeToRegExp ( url , { caseInsensitiveMatch : true } ) ;
1667
1670
return $httpBackend . when ( method , pathObj . regexp , undefined , undefined , pathObj . keys ) ;
1668
1671
} ;
1669
1672
1670
- function parseRoute ( url ) {
1671
- var ret = {
1672
- regexp : url
1673
- } ,
1674
- keys = ret . keys = [ ] ;
1675
-
1676
- if ( ! url || ! angular . isString ( url ) ) return ret ;
1677
-
1678
- url = url
1679
- . replace ( / ( [ ( ) . ] ) / g, '\\$1' )
1680
- . replace ( / ( \/ ) ? : ( \w + ) ( [ ? * ] ) ? / g, function ( _ , slash , key , option ) {
1681
- var optional = option === '?' ? option : null ;
1682
- var star = option === '*' ? option : null ;
1683
- keys . push ( { name : key , optional : ! ! optional } ) ;
1684
- slash = slash || '' ;
1685
- return ''
1686
- + ( optional ? '' : slash )
1687
- + '(?:'
1688
- + ( optional ? slash : '' )
1689
- + ( star && '(.+?)' || '([^/]+)' )
1690
- + ( optional || '' )
1691
- + ')'
1692
- + ( optional || '' ) ;
1693
- } )
1694
- . replace ( / ( [ / $ * ] ) / g, '\\$1' ) ;
1695
-
1696
- ret . regexp = new RegExp ( '^' + url , 'i' ) ;
1697
- return ret ;
1698
- }
1699
-
1700
1673
/**
1701
1674
* @ngdoc method
1702
1675
* @name $httpBackend#expect
@@ -1717,14 +1690,15 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1717
1690
* order to change how a matched request is handled.
1718
1691
*
1719
1692
* - respond –
1720
- * ```
1721
- * { function([status,] data[, headers, statusText])
1722
- * | function(function(method, url, data, headers, params)}
1723
- * ```
1693
+ * ```js
1694
+ * { function([status,] data[, headers, statusText])
1695
+ * | function(function(method, url, data, headers, params)}
1696
+ * ```
1724
1697
* – The respond method takes a set of static data to be returned or a function that can
1725
1698
* return an array containing response status (number), response data (Array|Object|string),
1726
- * response headers (Object), and the text for the status (string). The respond method returns
1727
- * the `requestHandler` object for possible overrides.
1699
+ * response headers (Object), HTTP status text (string), and XMLHttpRequest status (string:
1700
+ * `complete`, `error`, `timeout` or `abort`). The respond method returns the `requestHandler`
1701
+ * object for possible overrides.
1728
1702
*/
1729
1703
$httpBackend . expect = function ( method , url , data , headers , keys ) {
1730
1704
@@ -1876,7 +1850,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1876
1850
* See {@link ngMock.$httpBackend#expect `expect`} for more info.
1877
1851
*/
1878
1852
$httpBackend . expectRoute = function ( method , url ) {
1879
- var pathObj = parseRoute ( url ) ;
1853
+ var pathObj = routeToRegExp ( url , { caseInsensitiveMatch : true } ) ;
1880
1854
return $httpBackend . expect ( method , pathObj . regexp , undefined , undefined , pathObj . keys ) ;
1881
1855
} ;
1882
1856
0 commit comments