aboutsummaryrefslogtreecommitdiffstats
path: root/test/angular-mocksSpec.js
diff options
context:
space:
mode:
authorVojta Jina2011-11-01 13:27:42 -0700
committerIgor Minar2011-11-30 11:17:24 -0500
commit6290bd4587d9752c3b9eabacd20c90010cc330e3 (patch)
tree0b0a25505fb4b4892648d46a3a770c21e340dd08 /test/angular-mocksSpec.js
parente9f81b66316854bdd3a8548f028a64e86fc3e73c (diff)
downloadangular.js-6290bd4587d9752c3b9eabacd20c90010cc330e3.tar.bz2
refactor(mock.$httpBackend): rename when().then() to when().respond()
Diffstat (limited to 'test/angular-mocksSpec.js')
-rw-r--r--test/angular-mocksSpec.js62
1 files changed, 31 insertions, 31 deletions
diff --git a/test/angular-mocksSpec.js b/test/angular-mocksSpec.js
index 5b24c440..01c1b6ca 100644
--- a/test/angular-mocksSpec.js
+++ b/test/angular-mocksSpec.js
@@ -380,8 +380,8 @@ describe('mocks', function() {
it('should respond with first matched definition', function() {
- hb.when('GET', '/url1').then(200, 'content', {});
- hb.when('GET', '/url1').then(201, 'another', {});
+ hb.when('GET', '/url1').respond(200, 'content', {});
+ hb.when('GET', '/url1').respond(201, 'another', {});
callback.andCallFake(function(status, response) {
expect(status).toBe(200);
@@ -396,7 +396,7 @@ describe('mocks', function() {
it('should throw error when unexpected request', function() {
- hb.when('GET', '/url1').then(200, 'content');
+ hb.when('GET', '/url1').respond(200, 'content');
expect(function() {
hb('GET', '/xxx');
}).toThrow('Unexpected request: GET /xxx');
@@ -404,9 +404,9 @@ describe('mocks', function() {
it('should match headers if specified', function() {
- hb.when('GET', '/url', null, {'X': 'val1'}).then(201, 'content1');
- hb.when('GET', '/url', null, {'X': 'val2'}).then(202, 'content2');
- hb.when('GET', '/url').then(203, 'content3');
+ hb.when('GET', '/url', null, {'X': 'val1'}).respond(201, 'content1');
+ hb.when('GET', '/url', null, {'X': 'val2'}).respond(202, 'content2');
+ hb.when('GET', '/url').respond(203, 'content3');
hb('GET', '/url', null, function(status, response) {
expect(status).toBe(203);
@@ -428,8 +428,8 @@ describe('mocks', function() {
it('should match data if specified', function() {
- hb.when('GET', '/a/b', '{a: true}').then(201, 'content1');
- hb.when('GET', '/a/b').then(202, 'content2');
+ hb.when('GET', '/a/b', '{a: true}').respond(201, 'content1');
+ hb.when('GET', '/a/b').respond(202, 'content2');
hb('GET', '/a/b', '{a: true}', function(status, response) {
expect(status).toBe(201);
@@ -446,7 +446,7 @@ describe('mocks', function() {
it('should match only method', function() {
- hb.when('GET').then(202, 'c');
+ hb.when('GET').respond(202, 'c');
callback.andCallFake(function(status, response) {
expect(status).toBe(202);
expect(response).toBe('c');
@@ -462,7 +462,7 @@ describe('mocks', function() {
it('should expose given headers', function() {
- hb.when('GET', '/u1').then(200, null, {'X-Fake': 'Header', 'Content-Type': 'application/json'});
+ hb.when('GET', '/u1').respond(200, null, {'X-Fake': 'Header', 'Content-Type': 'application/json'});
var xhr = hb('GET', '/u1', null, noop, {});
hb.flush();
expect(xhr.getResponseHeader('X-Fake')).toBe('Header');
@@ -471,8 +471,8 @@ describe('mocks', function() {
it('should preserve the order of requests', function() {
- hb.when('GET', '/url1').then(200, 'first');
- hb.when('GET', '/url2').then(201, 'second');
+ hb.when('GET', '/url1').respond(200, 'first');
+ hb.when('GET', '/url2').respond(201, 'second');
hb('GET', '/url2', null, callback);
hb('GET', '/url1', null, callback);
@@ -485,8 +485,8 @@ describe('mocks', function() {
});
- it('then() should take function', function() {
- hb.when('GET', '/some').then(function(m, u, d, h) {
+ it('respond() should take function', function() {
+ hb.when('GET', '/some').respond(function(m, u, d, h) {
return [301, m + u + ';' + d + ';a=' + h.a, {'Connection': 'keep-alive'}];
});
@@ -516,7 +516,7 @@ describe('mocks', function() {
expect(response).toBe('expect');
});
- hb.when('GET', '/url').then(200, 'when');
+ hb.when('GET', '/url').respond(200, 'when');
hb.expect('GET', '/url').respond(300, 'expect');
hb('GET', '/url', null, callback, {});
@@ -526,7 +526,7 @@ describe('mocks', function() {
it ('should throw exception when only headers differes from expectation', function() {
- hb.when('GET').then(200, '', {});
+ hb.when('GET').respond(200, '', {});
hb.expect('GET', '/match', undefined, {'Content-Type': 'application/json'});
expect(function() {
@@ -537,7 +537,7 @@ describe('mocks', function() {
it ('should throw exception when only data differes from expectation', function() {
- hb.when('GET').then(200, '', {});
+ hb.when('GET').respond(200, '', {});
hb.expect('GET', '/match', 'some-data');
expect(function() {
@@ -547,13 +547,13 @@ describe('mocks', function() {
});
- it('expect() should without respond() and use then()', function() {
+ it('expect() should without respond() and use respond()', function() {
callback.andCallFake(function(status, response) {
expect(status).toBe(201);
expect(response).toBe('data');
});
- hb.when('GET', '/some').then(201, 'data');
+ hb.when('GET', '/some').respond(201, 'data');
hb.expect('GET', '/some');
hb('GET', '/some', null, callback);
hb.flush();
@@ -564,7 +564,7 @@ describe('mocks', function() {
it('flush() should flush requests fired during callbacks', function() {
- hb.when('GET').then(200, '');
+ hb.when('GET').respond(200, '');
hb('GET', '/some', null, function() {
hb('GET', '/other', null, callback);
});
@@ -575,7 +575,7 @@ describe('mocks', function() {
it('flush() should flush given number of pending requests', function() {
- hb.when('GET').then(200, '');
+ hb.when('GET').respond(200, '');
hb('GET', '/some', null, callback);
hb('GET', '/some', null, callback);
hb('GET', '/some', null, callback);
@@ -587,7 +587,7 @@ describe('mocks', function() {
it('flush() should throw exception when flushing more requests than pending', function() {
- hb.when('GET').then(200, '');
+ hb.when('GET').respond(200, '');
hb('GET', '/url', null, callback);
expect(function() {hb.flush(2);}).toThrow('No more pending request to flush !');
@@ -598,7 +598,7 @@ describe('mocks', function() {
it('(flush) should throw exception when no request to flush', function() {
expect(function() {hb.flush();}).toThrow('No pending request to flush !');
- hb.when('GET').then(200, '');
+ hb.when('GET').respond(200, '');
hb('GET', '/some', null, callback);
hb.flush();
@@ -622,14 +622,14 @@ describe('mocks', function() {
});
- it('then() should set default status 200 if not defined', function() {
+ it('respond() should set default status 200 if not defined', function() {
callback.andCallFake(function(status, response) {
expect(status).toBe(200);
expect(response).toBe('some-data');
});
- hb.when('GET', '/url1').then('some-data');
- hb.when('GET', '/url2').then('some-data', {'X-Header': 'true'});
+ hb.when('GET', '/url1').respond('some-data');
+ hb.when('GET', '/url2').respond('some-data', {'X-Header': 'true'});
hb('GET', '/url1', null, callback);
hb('GET', '/url2', null, callback);
hb.flush();
@@ -644,7 +644,7 @@ describe('mocks', function() {
expect(response).toBe('def-response');
});
- hb.when('GET').then(201, 'def-response');
+ hb.when('GET').respond(201, 'def-response');
hb.expect('GET', '/some-url');
hb('GET', '/some-url', null, callback);
@@ -671,7 +671,7 @@ describe('mocks', function() {
it('should respond undefined when JSONP method', function() {
- hb.when('JSONP', '/url1').then(200);
+ hb.when('JSONP', '/url1').respond(200);
hb.expect('JSONP', '/url2').respond(200);
expect(hb('JSONP', '/url1')).toBeUndefined();
@@ -694,7 +694,7 @@ describe('mocks', function() {
it('should do nothing when no expectation', function() {
- hb.when('DELETE', '/some').then(200, '');
+ hb.when('DELETE', '/some').respond(200, '');
expect(function() {hb.verifyNoOutstandingExpectation();}).not.toThrow();
});
@@ -703,7 +703,7 @@ describe('mocks', function() {
it('should do nothing when all expectations satisfied', function() {
hb.expect('GET', '/u2').respond(200, '', {});
hb.expect('POST', '/u3').respond(201, '', {});
- hb.when('DELETE', '/some').then(200, '');
+ hb.when('DELETE', '/some').respond(200, '');
hb('GET', '/u2', noop);
hb('POST', '/u3', noop);
@@ -715,7 +715,7 @@ describe('mocks', function() {
describe('verifyRequests', function() {
it('should throw exception if not all requests were flushed', function() {
- hb.when('GET').then(200);
+ hb.when('GET').respond(200);
hb('GET', '/some', null, noop, {});
expect(function() {