mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-18 23:50:23 +00:00
feat(mock.$httpBackend): add verifyNoOutstandingRequest method
+ rename verifyExpectations to verifyNoOutstandingExpectation
This commit is contained in:
parent
7b705df2b7
commit
afbe073121
4 changed files with 28 additions and 10 deletions
8
src/angular-mocks.js
vendored
8
src/angular-mocks.js
vendored
|
|
@ -664,12 +664,18 @@ angular.module.ngMock.$HttpBackendProvider = function() {
|
|||
}
|
||||
};
|
||||
|
||||
$httpBackend.verifyExpectations = function() {
|
||||
$httpBackend.verifyNoOutstandingExpectation = function() {
|
||||
if (expectations.length) {
|
||||
throw Error('Unsatisfied requests: ' + expectations.join(', '));
|
||||
}
|
||||
};
|
||||
|
||||
$httpBackend.verifyNoOutstandingRequest = function() {
|
||||
if (responses.length) {
|
||||
throw Error('Unflushed requests: ' + responses.length);
|
||||
}
|
||||
};
|
||||
|
||||
$httpBackend.resetExpectations = function() {
|
||||
expectations = [];
|
||||
responses = [];
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ describe("resource", function() {
|
|||
);
|
||||
|
||||
afterEach(inject(function($httpBackend) {
|
||||
$httpBackend.verifyExpectations();
|
||||
$httpBackend.verifyNoOutstandingExpectation();
|
||||
}));
|
||||
|
||||
it("should build resource", function() {
|
||||
|
|
|
|||
26
test/angular-mocksSpec.js
vendored
26
test/angular-mocksSpec.js
vendored
|
|
@ -559,7 +559,7 @@ describe('mocks', function() {
|
|||
hb.flush();
|
||||
|
||||
expect(callback).toHaveBeenCalled();
|
||||
expect(function() { hb.verifyExpectations(); }).not.toThrow();
|
||||
expect(function() { hb.verifyNoOutstandingExpectation(); }).not.toThrow();
|
||||
});
|
||||
|
||||
|
||||
|
|
@ -651,7 +651,7 @@ describe('mocks', function() {
|
|||
hb('GET', '/some-url', null, callback);
|
||||
hb.flush();
|
||||
expect(callback).toHaveBeenCalledOnce();
|
||||
hb.verifyExpectations();
|
||||
hb.verifyNoOutstandingExpectation();
|
||||
});
|
||||
|
||||
|
||||
|
|
@ -680,7 +680,7 @@ describe('mocks', function() {
|
|||
});
|
||||
|
||||
|
||||
describe('verify', function() {
|
||||
describe('verifyExpectations', function() {
|
||||
|
||||
it('should throw exception if not all expectations were satisfied', function() {
|
||||
hb.expect('POST', '/u1', 'ddd').respond(201, '', {});
|
||||
|
|
@ -689,7 +689,7 @@ describe('mocks', function() {
|
|||
|
||||
hb('POST', '/u1', 'ddd', noop, {});
|
||||
|
||||
expect(function() {hb.verifyExpectations();})
|
||||
expect(function() {hb.verifyNoOutstandingExpectation();})
|
||||
.toThrow('Unsatisfied requests: GET /u2, POST /u3');
|
||||
});
|
||||
|
||||
|
|
@ -697,7 +697,7 @@ describe('mocks', function() {
|
|||
it('should do nothing when no expectation', function() {
|
||||
hb.when('DELETE', '/some').then(200, '');
|
||||
|
||||
expect(function() {hb.verifyExpectations();}).not.toThrow();
|
||||
expect(function() {hb.verifyNoOutstandingExpectation();}).not.toThrow();
|
||||
});
|
||||
|
||||
|
||||
|
|
@ -709,7 +709,19 @@ describe('mocks', function() {
|
|||
hb('GET', '/u2', noop);
|
||||
hb('POST', '/u3', noop);
|
||||
|
||||
expect(function() {hb.verifyExpectations();}).not.toThrow();
|
||||
expect(function() {hb.verifyNoOutstandingExpectation();}).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('verifyRequests', function() {
|
||||
|
||||
it('should throw exception if not all requests were flushed', function() {
|
||||
hb.when('GET').then(200);
|
||||
hb('GET', '/some', null, noop, {});
|
||||
|
||||
expect(function() {
|
||||
hb.verifyNoOutstandingRequest();
|
||||
}).toThrow('Unflushed requests: 1');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -721,7 +733,7 @@ describe('mocks', function() {
|
|||
hb.expect('POST', '/u3').respond(201, '', {});
|
||||
hb.resetExpectations();
|
||||
|
||||
expect(function() {hb.verifyExpectations();}).not.toThrow();
|
||||
expect(function() {hb.verifyNoOutstandingExpectation();}).not.toThrow();
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ describe('$http', function() {
|
|||
|
||||
afterEach(function() {
|
||||
if ($exceptionHandler.errors.length) throw $exceptionHandler.errors;
|
||||
$httpBackend.verifyExpectations();
|
||||
$httpBackend.verifyNoOutstandingExpectation();
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue