Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit afbe073

Browse files
vojtajinaIgorMinar
authored andcommitted
feat(mock.$httpBackend): add verifyNoOutstandingRequest method
+ rename verifyExpectations to verifyNoOutstandingExpectation
1 parent 7b705df commit afbe073

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

src/angular-mocks.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,12 +664,18 @@ angular.module.ngMock.$HttpBackendProvider = function() {
664664
}
665665
};
666666

667-
$httpBackend.verifyExpectations = function() {
667+
$httpBackend.verifyNoOutstandingExpectation = function() {
668668
if (expectations.length) {
669669
throw Error('Unsatisfied requests: ' + expectations.join(', '));
670670
}
671671
};
672672

673+
$httpBackend.verifyNoOutstandingRequest = function() {
674+
if (responses.length) {
675+
throw Error('Unflushed requests: ' + responses.length);
676+
}
677+
};
678+
673679
$httpBackend.resetExpectations = function() {
674680
expectations = [];
675681
responses = [];

test/ResourceSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe("resource", function() {
2020
);
2121

2222
afterEach(inject(function($httpBackend) {
23-
$httpBackend.verifyExpectations();
23+
$httpBackend.verifyNoOutstandingExpectation();
2424
}));
2525

2626
it("should build resource", function() {

test/angular-mocksSpec.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ describe('mocks', function() {
559559
hb.flush();
560560

561561
expect(callback).toHaveBeenCalled();
562-
expect(function() { hb.verifyExpectations(); }).not.toThrow();
562+
expect(function() { hb.verifyNoOutstandingExpectation(); }).not.toThrow();
563563
});
564564

565565

@@ -651,7 +651,7 @@ describe('mocks', function() {
651651
hb('GET', '/some-url', null, callback);
652652
hb.flush();
653653
expect(callback).toHaveBeenCalledOnce();
654-
hb.verifyExpectations();
654+
hb.verifyNoOutstandingExpectation();
655655
});
656656

657657

@@ -680,7 +680,7 @@ describe('mocks', function() {
680680
});
681681

682682

683-
describe('verify', function() {
683+
describe('verifyExpectations', function() {
684684

685685
it('should throw exception if not all expectations were satisfied', function() {
686686
hb.expect('POST', '/u1', 'ddd').respond(201, '', {});
@@ -689,15 +689,15 @@ describe('mocks', function() {
689689

690690
hb('POST', '/u1', 'ddd', noop, {});
691691

692-
expect(function() {hb.verifyExpectations();})
692+
expect(function() {hb.verifyNoOutstandingExpectation();})
693693
.toThrow('Unsatisfied requests: GET /u2, POST /u3');
694694
});
695695

696696

697697
it('should do nothing when no expectation', function() {
698698
hb.when('DELETE', '/some').then(200, '');
699699

700-
expect(function() {hb.verifyExpectations();}).not.toThrow();
700+
expect(function() {hb.verifyNoOutstandingExpectation();}).not.toThrow();
701701
});
702702

703703

@@ -709,7 +709,19 @@ describe('mocks', function() {
709709
hb('GET', '/u2', noop);
710710
hb('POST', '/u3', noop);
711711

712-
expect(function() {hb.verifyExpectations();}).not.toThrow();
712+
expect(function() {hb.verifyNoOutstandingExpectation();}).not.toThrow();
713+
});
714+
});
715+
716+
describe('verifyRequests', function() {
717+
718+
it('should throw exception if not all requests were flushed', function() {
719+
hb.when('GET').then(200);
720+
hb('GET', '/some', null, noop, {});
721+
722+
expect(function() {
723+
hb.verifyNoOutstandingRequest();
724+
}).toThrow('Unflushed requests: 1');
713725
});
714726
});
715727

@@ -721,7 +733,7 @@ describe('mocks', function() {
721733
hb.expect('POST', '/u3').respond(201, '', {});
722734
hb.resetExpectations();
723735

724-
expect(function() {hb.verifyExpectations();}).not.toThrow();
736+
expect(function() {hb.verifyNoOutstandingExpectation();}).not.toThrow();
725737
});
726738

727739

test/service/httpSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('$http', function() {
1919

2020
afterEach(function() {
2121
if ($exceptionHandler.errors.length) throw $exceptionHandler.errors;
22-
$httpBackend.verifyExpectations();
22+
$httpBackend.verifyNoOutstandingExpectation();
2323
});
2424

2525

0 commit comments

Comments
 (0)