mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-01-12 22:45:52 +08:00
committed by
Lucas Galfaso
parent
ed1243ffc7
commit
acb066e84a
10
src/ngMock/angular-mocks.js
vendored
10
src/ngMock/angular-mocks.js
vendored
@@ -1112,7 +1112,7 @@ angular.mock.dump = function(object) {
|
||||
```
|
||||
*/
|
||||
angular.mock.$HttpBackendProvider = function() {
|
||||
this.$get = ['$rootScope', createHttpBackendMock];
|
||||
this.$get = ['$rootScope', '$timeout', createHttpBackendMock];
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1129,7 +1129,7 @@ angular.mock.$HttpBackendProvider = function() {
|
||||
* @param {Object=} $browser Auto-flushing enabled if specified
|
||||
* @return {Object} Instance of $httpBackend mock
|
||||
*/
|
||||
function createHttpBackendMock($rootScope, $delegate, $browser) {
|
||||
function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
|
||||
var definitions = [],
|
||||
expectations = [],
|
||||
responses = [],
|
||||
@@ -1159,7 +1159,9 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
|
||||
}
|
||||
|
||||
function wrapResponse(wrapped) {
|
||||
if (!$browser && timeout && timeout.then) timeout.then(handleTimeout);
|
||||
if (!$browser && timeout) {
|
||||
timeout.then ? timeout.then(handleTimeout) : $timeout(handleTimeout, timeout);
|
||||
}
|
||||
|
||||
return handleResponse;
|
||||
|
||||
@@ -2033,7 +2035,7 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
|
||||
*/
|
||||
angular.mock.e2e = {};
|
||||
angular.mock.e2e.$httpBackendDecorator =
|
||||
['$rootScope', '$delegate', '$browser', createHttpBackendMock];
|
||||
['$rootScope', '$timeout', '$delegate', '$browser', createHttpBackendMock];
|
||||
|
||||
|
||||
/**
|
||||
|
||||
12
test/ngMock/angular-mocksSpec.js
vendored
12
test/ngMock/angular-mocksSpec.js
vendored
@@ -1310,6 +1310,18 @@ describe('ngMock', function() {
|
||||
});
|
||||
|
||||
|
||||
it('should abort requests when timeout passed as a numeric value', inject(function($timeout) {
|
||||
hb.expect('GET', '/url1').respond(200);
|
||||
|
||||
hb('GET', '/url1', null, callback, null, 200);
|
||||
$timeout.flush(300);
|
||||
|
||||
expect(callback).toHaveBeenCalledWith(-1, undefined, '');
|
||||
hb.verifyNoOutstandingExpectation();
|
||||
hb.verifyNoOutstandingRequest();
|
||||
}));
|
||||
|
||||
|
||||
it('should throw an exception if no response defined', function() {
|
||||
hb.when('GET', '/test');
|
||||
expect(function() {
|
||||
|
||||
Reference in New Issue
Block a user