mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
feat(mock.$httpBackend): verify expectations after flush()
This commit is contained in:
parent
6290bd4587
commit
4aaa2f7f6b
3 changed files with 14 additions and 5 deletions
1
src/angular-mocks.js
vendored
1
src/angular-mocks.js
vendored
|
|
@ -667,6 +667,7 @@ angular.module.ngMock.$HttpBackendProvider = function() {
|
|||
while (responses.length)
|
||||
responses.shift()();
|
||||
}
|
||||
$httpBackend.verifyNoOutstandingExpectation();
|
||||
};
|
||||
|
||||
$httpBackend.verifyNoOutstandingExpectation = function() {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
9
test/angular-mocksSpec.js
vendored
9
test/angular-mocksSpec.js
vendored
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue