aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVojta Jina2011-11-01 13:40:51 -0700
committerIgor Minar2011-11-30 11:17:24 -0500
commit4aaa2f7f6b37f0ad8255e6a320e9136a89e329de (patch)
treec29156be96432abcaafee933e01085d1a4b4948f
parent6290bd4587d9752c3b9eabacd20c90010cc330e3 (diff)
downloadangular.js-4aaa2f7f6b37f0ad8255e6a320e9136a89e329de.tar.bz2
feat(mock.$httpBackend): verify expectations after flush()
-rw-r--r--src/angular-mocks.js1
-rw-r--r--test/ResourceSpec.js9
-rw-r--r--test/angular-mocksSpec.js9
3 files changed, 14 insertions, 5 deletions
diff --git a/src/angular-mocks.js b/src/angular-mocks.js
index d9535f64..60211e6f 100644
--- a/src/angular-mocks.js
+++ b/src/angular-mocks.js
@@ -667,6 +667,7 @@ angular.module.ngMock.$HttpBackendProvider = function() {
while (responses.length)
responses.shift()();
}
+ $httpBackend.verifyNoOutstandingExpectation();
};
$httpBackend.verifyNoOutstandingExpectation = function() {
diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js
index fd7e41db..7987af04 100644
--- a/test/ResourceSpec.js
+++ b/test/ResourceSpec.js
@@ -125,8 +125,6 @@ describe("resource", function() {
it("should read partial resource", inject(function($httpBackend) {
$httpBackend.expect('GET', '/CreditCard').respond([{id:{key:123}}]);
- $httpBackend.expect('GET', '/CreditCard/123').respond({id: {key: 123}, number: '9876'});
-
var ccs = CreditCard.query();
$httpBackend.flush();
@@ -136,6 +134,7 @@ describe("resource", function() {
expect(cc instanceof CreditCard).toBe(true);
expect(cc.number).toBeUndefined();
+ $httpBackend.expect('GET', '/CreditCard/123').respond({id: {key: 123}, number: '9876'});
cc.$get(callback);
$httpBackend.flush();
expect(callback).toHaveBeenCalledWith(cc);
@@ -177,8 +176,6 @@ describe("resource", function() {
it('should delete resource and call callback', inject(function($httpBackend) {
$httpBackend.expect('DELETE', '/CreditCard/123').respond({});
- $httpBackend.expect('DELETE', '/CreditCard/333').respond(204, null);
-
CreditCard.remove({id:123}, callback);
expect(callback).not.toHaveBeenCalled();
@@ -186,6 +183,7 @@ describe("resource", function() {
nakedExpect(callback.mostRecentCall.args).toEqual([{}]);
callback.reset();
+ $httpBackend.expect('DELETE', '/CreditCard/333').respond(204, null);
CreditCard.remove({id:333}, callback);
expect(callback).not.toHaveBeenCalled();
@@ -227,13 +225,14 @@ describe("resource", function() {
it('should not mutate the resource object if response contains no body', inject(function($httpBackend) {
var data = {id:{key:123}, number:'9876'};
$httpBackend.expect('GET', '/CreditCard/123').respond(data);
- $httpBackend.expect('POST', '/CreditCard/123', toJson(data)).respond('');
var cc = CreditCard.get({id:123});
$httpBackend.flush();
expect(cc instanceof CreditCard).toBe(true);
+ $httpBackend.expect('POST', '/CreditCard/123', toJson(data)).respond('');
var idBefore = cc.id;
+
cc.$save();
$httpBackend.flush();
expect(idBefore).toEqual(cc.id);
diff --git a/test/angular-mocksSpec.js b/test/angular-mocksSpec.js
index 01c1b6ca..6b6f0052 100644
--- a/test/angular-mocksSpec.js
+++ b/test/angular-mocksSpec.js
@@ -606,6 +606,15 @@ describe('mocks', function() {
});
+ it('(flush) should throw exception if not all expectations satasfied', function() {
+ hb.expect('GET', '/url1').respond();
+ hb.expect('GET', '/url2').respond();
+
+ hb('GET', '/url1', null, angular.noop);
+ expect(function() {hb.flush();}).toThrow('Unsatisfied requests: GET /url2');
+ });
+
+
it('respond() should set default status 200 if not defined', function() {
callback.andCallFake(function(status, response) {
expect(status).toBe(200);