Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(430)

Unified Diff: third_party/pkg/angular/test/mock/http_backend_spec.dart

Issue 257423008: Update all Angular libs (run update_all.sh). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/pkg/angular/test/mock/http_backend_spec.dart
diff --git a/third_party/pkg/angular/test/mock/http_backend_spec.dart b/third_party/pkg/angular/test/mock/http_backend_spec.dart
index 65ff89b1941bcb09abca7ee02090016e374b6272..763e5b22fe262c913f4b265bb8f6b8681265cf3a 100644
--- a/third_party/pkg/angular/test/mock/http_backend_spec.dart
+++ b/third_party/pkg/angular/test/mock/http_backend_spec.dart
@@ -11,468 +11,469 @@ class _Chain {
then(x) => _thenFn(x);
}
-main() => describe('MockHttpBackend', () {
- TestBed _;
- beforeEach(inject((TestBed tb) => _ = tb));
+void main() {
+ describe('MockHttpBackend', () {
+ TestBed _;
+ beforeEach((TestBed tb) => _ = tb);
- var hb, callback, realBackendSpy;
+ var hb, callback, realBackendSpy;
- var noop = (_, __) {};
- var undefined = null;
+ var noop = (_, __) {};
+ var undefined = null;
- beforeEach(inject((HttpBackend httpBackend) {
- callback = jasmine.createSpy('callback');
- hb = httpBackend;
- }));
-
-
- it('should respond with first matched definition', () {
- hb.when('GET', '/url1').respond(200, 'content', {});
- hb.when('GET', '/url1').respond(201, 'another', {});
-
- callback.andCallFake((status, response) {
- expect(status).toBe(200);
- expect(response).toBe('content');
+ beforeEach((HttpBackend httpBackend) {
+ callback = jasmine.createSpy('callback');
+ hb = httpBackend;
});
- hb('GET', '/url1', null, callback);
- expect(callback).not.toHaveBeenCalled();
- hb.flush();
- expect(callback).toHaveBeenCalledOnce();
- });
-
- it('should respond with JSON', inject((Logger logger) {
- hb.when('GET', '/url1').respond(200, ['abc'], {});
- hb.when('GET', '/url2').respond(200, {'key': 'value'}, {});
+ it('should respond with first matched definition', () {
+ hb.when('GET', '/url1').respond(200, 'content', {});
+ hb.when('GET', '/url1').respond(201, 'another', {});
+ callback.andCallFake((status, response) {
+ expect(status).toBe(200);
+ expect(response).toBe('content');
+ });
- callback.andCallFake((status, response) {
- expect(status).toBe(200);
- logger(response);
+ hb('GET', '/url1', null, callback);
+ expect(callback).not.toHaveBeenCalled();
+ hb.flush();
+ expect(callback).toHaveBeenCalledOnce();
});
- hb('GET', '/url1', null, callback);
- hb('GET', '/url2', null, callback);
- hb.flush();
- expect(logger).toEqual(['["abc"]', '{"key":"value"}']);
- }));
-
- it('should throw error when unexpected request', () {
- hb.when('GET', '/url1').respond(200, 'content');
- expect(() {
- hb('GET', '/xxx');
- }).toThrow('Unexpected request: GET /xxx\nNo more requests expected');
- });
+ it('should respond with JSON', (Logger logger) {
+ hb.when('GET', '/url1').respond(200, ['abc'], {});
+ hb.when('GET', '/url2').respond(200, {'key': 'value'}, {});
- it('should throw an error on an exception in then', async(() {
- hb.expectGET('/url').respond(200, 'content');
-
- expect(() {
- hb.request('/url', method: 'GET').then((x) {
- throw ["exceptiona"];
+ callback.andCallFake((status, response) {
+ expect(status).toBe(200);
+ logger(response);
});
- hb.flush();
- microLeap();
- }).toThrow('exceptiona');
- }));
-
-
- it('should match headers if specified', () {
- try {
- 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, (status, response) {
- expect(status).toBe(203);
- expect(response).toBe('content3');
+ hb('GET', '/url1', null, callback);
+ hb('GET', '/url2', null, callback);
+ hb.flush();
+ expect(logger).toEqual(['["abc"]', '{"key":"value"}']);
});
- hb('GET', '/url', null, (status, response) {
- expect(status).toBe(201);
- expect(response).toBe('content1');
- }, {'X': 'val1'});
-
- hb('GET', '/url', null, (status, response) {
- expect(status).toBe(202);
- expect(response).toBe('content2');
- }, {'X': 'val2'});
-
- hb.flush();
- } catch (e,s) { print("$e $s"); }
- });
-
-
- it('should match data if specified', () {
- hb.when('GET', '/a/b', '{a: true}').respond(201, 'content1');
- hb.when('GET', '/a/b').respond(202, 'content2');
-
- hb('GET', '/a/b', '{a: true}', (status, response) {
- expect(status).toBe(201);
- expect(response).toBe('content1');
- });
- hb('GET', '/a/b', '{}', (status, response) {
- expect(status).toBe(202);
- expect(response).toBe('content2');
+ it('should throw error when unexpected request', () {
+ hb.when('GET', '/url1').respond(200, 'content');
+ expect(() {
+ hb('GET', '/xxx');
+ }).toThrow('Unexpected request: GET /xxx\nNo more requests expected');
});
- hb.flush();
- });
+ it('should throw an error on an exception in then', async(() {
+ hb.expectGET('/url').respond(200, 'content');
- it('should match only method', () {
- hb.when('GET').respond(202, 'c');
- callback.andCallFake((status, response) {
- expect(status).toBe(202);
- expect(response).toBe('c');
- });
-
- hb('GET', '/some', null, callback, {});
- hb('GET', '/another', null, callback, {'X-Fake': 'Header'});
- hb('GET', '/third', 'some-data', callback, {});
- hb.flush();
+ expect(() {
+ hb.request('/url', method: 'GET').then((x) {
+ throw ["exceptiona"];
+ });
+ hb.flush();
+ microLeap();
+ }).toThrow('exceptiona');
+ }));
- expect(callback).toHaveBeenCalled();
- });
+ it('should match headers if specified', () {
+ try {
+ 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');
- it('should preserve the order of requests', () {
- hb.when('GET', '/url1').respond(200, 'first');
- hb.when('GET', '/url2').respond(201, 'second');
+ hb('GET', '/url', null, (status, response) {
+ expect(status).toBe(203);
+ expect(response).toBe('content3');
+ });
- hb('GET', '/url2', null, callback);
- hb('GET', '/url1', null, callback);
+ hb('GET', '/url', null, (status, response) {
+ expect(status).toBe(201);
+ expect(response).toBe('content1');
+ }, {'X': 'val1'});
- hb.flush();
+ hb('GET', '/url', null, (status, response) {
+ expect(status).toBe(202);
+ expect(response).toBe('content2');
+ }, {'X': 'val2'});
- expect(callback.callCount).toBe(2);
- expect(callback.argsForCall[0]).toEqual([201, 'second', '']);
- expect(callback.argsForCall[1]).toEqual([200, 'first', '']);
- });
+ hb.flush();
+ } catch (e,s) { print("$e $s"); }
+ });
- describe('respond()', () {
- it('should take values', () {
- hb.expect('GET', '/url1').respond(200, 'first', {'header': 'val'});
- hb('GET', '/url1', null, callback);
- hb.flush();
+ it('should match data if specified', () {
+ hb.when('GET', '/a/b', '{a: true}').respond(201, 'content1');
+ hb.when('GET', '/a/b').respond(202, 'content2');
- expect(callback).toHaveBeenCalledOnceWith(200, 'first', "header: val");
- });
+ hb('GET', '/a/b', '{a: true}', (status, response) {
+ expect(status).toBe(201);
+ expect(response).toBe('content1');
+ });
- it('should take function', () {
- hb.expect('GET', '/some').respond((m, u, d, h) {
- return [301, m + u + ';' + d + ';a=' + h['a'], {'Connection': 'keep-alive'}];
+ hb('GET', '/a/b', '{}', (status, response) {
+ expect(status).toBe(202);
+ expect(response).toBe('content2');
});
- hb('GET', '/some', 'data', callback, {'a': 'b'});
hb.flush();
-
- expect(callback).toHaveBeenCalledOnceWith(301, 'GET/some;data;a=b', 'Connection: keep-alive');
});
- it('should default status code to 200', () {
+
+ it('should match only method', () {
+ hb.when('GET').respond(202, 'c');
callback.andCallFake((status, response) {
- expect(status).toBe(200);
- expect(response).toBe('some-data');
+ expect(status).toBe(202);
+ expect(response).toBe('c');
});
- hb.expect('GET', '/url1').respond('some-data');
- hb.expect('GET', '/url2').respond('some-data', {'X-Header': 'true'});
- hb('GET', '/url1', null, callback);
- hb('GET', '/url2', null, callback);
+ hb('GET', '/some', null, callback, {});
+ hb('GET', '/another', null, callback, {'X-Fake': 'Header'});
+ hb('GET', '/third', 'some-data', callback, {});
hb.flush();
+
expect(callback).toHaveBeenCalled();
- expect(callback.callCount).toBe(2);
});
- it('should default response headers to ""', () {
- hb.expect('GET', '/url1').respond(200, 'first');
- hb.expect('GET', '/url2').respond('second');
+ it('should preserve the order of requests', () {
+ hb.when('GET', '/url1').respond(200, 'first');
+ hb.when('GET', '/url2').respond(201, 'second');
- hb('GET', '/url1', null, callback);
hb('GET', '/url2', null, callback);
+ hb('GET', '/url1', null, callback);
hb.flush();
expect(callback.callCount).toBe(2);
- expect(callback.argsForCall[0]).toEqual([200, 'first', '']);
- expect(callback.argsForCall[1]).toEqual([200, 'second', '']);
+ expect(callback.argsForCall[0]).toEqual([201, 'second', '']);
+ expect(callback.argsForCall[1]).toEqual([200, 'first', '']);
});
- });
- describe('expect()', () {
- it('should require specified order', () {
- hb.expect('GET', '/url1').respond(200, '');
- hb.expect('GET', '/url2').respond(200, '');
+ describe('respond()', () {
+ it('should take values', () {
+ hb.expect('GET', '/url1').respond(200, 'first', {'header': 'val'});
+ hb('GET', '/url1', null, callback);
+ hb.flush();
- expect(() {
- hb('GET', '/url2', null, noop, {});
- }).toThrow('Unexpected request: GET /url2\nExpected GET /url1');
- });
+ expect(callback).toHaveBeenCalledOnceWith(200, 'first', "header: val");
+ });
+ it('should take function', () {
+ hb.expect('GET', '/some').respond((m, u, d, h) {
+ return [301, m + u + ';' + d + ';a=' + h['a'], {'Connection': 'keep-alive'}];
+ });
- it('should have precedence over when()', () {
- callback.andCallFake((status, response) {
- expect(status).toBe(299);
- expect(response).toBe('expect');
+ hb('GET', '/some', 'data', callback, {'a': 'b'});
+ hb.flush();
+
+ expect(callback).toHaveBeenCalledOnceWith(301, 'GET/some;data;a=b', 'Connection: keep-alive');
});
- hb.when('GET', '/url').respond(200, 'when');
- hb.expect('GET', '/url').respond(299, 'expect');
+ it('should default status code to 200', () {
+ callback.andCallFake((status, response) {
+ expect(status).toBe(200);
+ expect(response).toBe('some-data');
+ });
- hb('GET', '/url', null, callback, null);
- hb.flush();
- expect(callback).toHaveBeenCalledOnce();
- });
+ hb.expect('GET', '/url1').respond('some-data');
+ hb.expect('GET', '/url2').respond('some-data', {'X-Header': 'true'});
+ hb('GET', '/url1', null, callback);
+ hb('GET', '/url2', null, callback);
+ hb.flush();
+ expect(callback).toHaveBeenCalled();
+ expect(callback.callCount).toBe(2);
+ });
- it('should throw exception when only headers differs from expectation', () {
- hb.when('GET', '/match').respond(200, '', {});
- hb.expect('GET', '/match', null, {'Content-Type': 'application/json'}).respond(200, '', {});
+ it('should default response headers to ""', () {
+ hb.expect('GET', '/url1').respond(200, 'first');
+ hb.expect('GET', '/url2').respond('second');
- expect(() {
- hb('GET', '/match', null, noop, {});
- }).toThrow('Expected GET /match with different headers\n' +
- 'EXPECTED: {"Content-Type":"application/json"}\nGOT: {}');
+ hb('GET', '/url1', null, callback);
+ hb('GET', '/url2', null, callback);
+
+ hb.flush();
+
+ expect(callback.callCount).toBe(2);
+ expect(callback.argsForCall[0]).toEqual([200, 'first', '']);
+ expect(callback.argsForCall[1]).toEqual([200, 'second', '']);
+ });
});
- it('should throw exception when only data differs from expectation', () {
- hb.when('GET', '/match').respond(200, '', {});
- hb.expect('GET', '/match', 'some-data').respond(200, '', {});
+ describe('expect()', () {
+ it('should require specified order', () {
+ hb.expect('GET', '/url1').respond(200, '');
+ hb.expect('GET', '/url2').respond(200, '');
- expect(() {
- hb('GET', '/match', 'different', noop, null);
- }).toThrow('Expected GET /match with different data\n' +
- 'EXPECTED: some-data\nGOT: different');
- });
+ expect(() {
+ hb('GET', '/url2', null, noop, {});
+ }).toThrow('Unexpected request: GET /url2\nExpected GET /url1');
+ });
- it("should use when's respond() when no expect() respond is defined", () {
- callback.andCallFake((status, response) {
- expect(status).toBe(201);
- expect(response).toBe('data');
+ it('should have precedence over when()', () {
+ callback.andCallFake((status, response) {
+ expect(status).toBe(299);
+ expect(response).toBe('expect');
+ });
+
+ hb.when('GET', '/url').respond(200, 'when');
+ hb.expect('GET', '/url').respond(299, 'expect');
+
+ hb('GET', '/url', null, callback, null);
+ hb.flush();
+ expect(callback).toHaveBeenCalledOnce();
});
- hb.when('GET', '/some').respond(201, 'data');
- hb.expect('GET', '/some');
- hb('GET', '/some', null, callback);
- hb.flush();
- expect(callback).toHaveBeenCalled();
- expect(() { hb.verifyNoOutstandingExpectation(); }).not.toThrow();
- });
- });
+ it('should throw exception when only headers differs from expectation', () {
+ hb.when('GET', '/match').respond(200, '', {});
+ hb.expect('GET', '/match', null, {'Content-Type': 'application/json'}).respond(200, '', {});
+
+ expect(() {
+ hb('GET', '/match', null, noop, {});
+ }).toThrow('Expected GET /match with different headers\n' +
+ 'EXPECTED: {"Content-Type":"application/json"}\nGOT: {}');
+ });
- describe('flush()', () {
- it('flush() should flush requests fired during callbacks', () {
- hb.when('GET', '/some').respond(200, '');
- hb.when('GET', '/other').respond(200, '');
- hb('GET', '/some', null, (_, __) {
- hb('GET', '/other', null, callback);
+ it('should throw exception when only data differs from expectation', () {
+ hb.when('GET', '/match').respond(200, '', {});
+ hb.expect('GET', '/match', 'some-data').respond(200, '', {});
+
+ expect(() {
+ hb('GET', '/match', 'different', noop, null);
+ }).toThrow('Expected GET /match with different data\n' +
+ 'EXPECTED: some-data\nGOT: different');
});
- hb.flush();
- expect(callback).toHaveBeenCalled();
- });
+ it("should use when's respond() when no expect() respond is defined", () {
+ callback.andCallFake((status, response) {
+ expect(status).toBe(201);
+ expect(response).toBe('data');
+ });
- it('should flush given number of pending requests', () {
- hb.when('GET').respond(200, '');
- hb('GET', '/some', null, callback);
- hb('GET', '/some', null, callback);
- hb('GET', '/some', null, callback);
+ hb.when('GET', '/some').respond(201, 'data');
+ hb.expect('GET', '/some');
+ hb('GET', '/some', null, callback);
+ hb.flush();
- hb.flush(2);
- expect(callback).toHaveBeenCalled();
- expect(callback.callCount).toBe(2);
+ expect(callback).toHaveBeenCalled();
+ expect(() { hb.verifyNoOutstandingExpectation(); }).not.toThrow();
+ });
});
- it('should throw exception when flushing more requests than pending', () {
- hb.when('GET').respond(200, '');
- hb('GET', '/url', null, callback);
+ describe('flush()', () {
+ it('flush() should flush requests fired during callbacks', () {
+ hb.when('GET', '/some').respond(200, '');
+ hb.when('GET', '/other').respond(200, '');
+ hb('GET', '/some', null, (_, __) {
+ hb('GET', '/other', null, callback);
+ });
- expect(() {hb.flush(2);}).toThrow('No more pending request to flush !');
- expect(callback).toHaveBeenCalledOnce();
- });
+ hb.flush();
+ expect(callback).toHaveBeenCalled();
+ });
- it('should throw exception when no request to flush', () {
- expect(() {hb.flush();}).toThrow('No pending request to flush !');
+ it('should flush given number of pending requests', () {
+ hb.when('GET').respond(200, '');
+ hb('GET', '/some', null, callback);
+ hb('GET', '/some', null, callback);
+ hb('GET', '/some', null, callback);
- hb.when('GET').respond(200, '');
- hb('GET', '/some', null, callback);
- hb.flush();
+ hb.flush(2);
+ expect(callback).toHaveBeenCalled();
+ expect(callback.callCount).toBe(2);
+ });
- expect(() {hb.flush();}).toThrow('No pending request to flush !');
- });
+ it('should throw exception when flushing more requests than pending', () {
+ hb.when('GET').respond(200, '');
+ hb('GET', '/url', null, callback);
- it('should throw exception if not all expectations satisfied', () {
- hb.expect('GET', '/url1').respond();
- hb.expect('GET', '/url2').respond();
+ expect(() {hb.flush(2);}).toThrow('No more pending request to flush !');
+ expect(callback).toHaveBeenCalledOnce();
+ });
- hb('GET', '/url1', null, noop);
- expect(() {hb.flush();}).toThrow('Unsatisfied requests: GET /url2');
- });
- });
+
+ it('should throw exception when no request to flush', () {
+ expect(() {hb.flush();}).toThrow('No pending request to flush !');
+
+ hb.when('GET').respond(200, '');
+ hb('GET', '/some', null, callback);
+ hb.flush();
+
+ expect(() {hb.flush();}).toThrow('No pending request to flush !');
+ });
- it('should abort requests when timeout promise resolves', () {
- hb.expect('GET', '/url1').respond(200);
+ it('should throw exception if not all expectations satisfied', () {
+ hb.expect('GET', '/url1').respond();
+ hb.expect('GET', '/url2').respond();
- var canceler, then = jasmine.createSpy('then').andCallFake((fn) {
- canceler = fn;
+ hb('GET', '/url1', null, noop);
+ expect(() {hb.flush();}).toThrow('Unsatisfied requests: GET /url2');
+ });
});
- hb('GET', '/url1', null, callback, null, new _Chain(then: then));
- expect(canceler is Function).toBe(true);
- canceler(); // simulate promise resolution
+ it('should abort requests when timeout promise resolves', () {
+ hb.expect('GET', '/url1').respond(200);
- expect(callback).toHaveBeenCalledWith(-1, null, '');
- hb.verifyNoOutstandingExpectation();
- hb.verifyNoOutstandingRequest();
- });
+ var canceler, then = jasmine.createSpy('then').andCallFake((fn) {
+ canceler = fn;
+ });
+ hb('GET', '/url1', null, callback, null, new _Chain(then: then));
+ expect(canceler is Function).toBe(true);
- it('should throw an exception if no response defined', () {
- hb.when('GET', '/test');
- expect(() {
- hb('GET', '/test', null, callback);
- }).toThrow('No response defined !');
- });
+ canceler(); // simulate promise resolution
+
+ expect(callback).toHaveBeenCalledWith(-1, null, '');
+ hb.verifyNoOutstandingExpectation();
+ hb.verifyNoOutstandingRequest();
+ });
- it('should throw an exception if no response for exception and no definition', () {
- hb.expect('GET', '/url');
- expect(() {
- hb('GET', '/url', null, callback);
- }).toThrow('No response defined !');
- });
+ it('should throw an exception if no response defined', () {
+ hb.when('GET', '/test');
+ expect(() {
+ hb('GET', '/test', null, callback);
+ }).toThrow('No response defined !');
+ });
- it('should respond undefined when JSONP method', () {
- hb.when('JSONP', '/url1').respond(200);
- hb.expect('JSONP', '/url2').respond(200);
+ it('should throw an exception if no response for exception and no definition', () {
+ hb.expect('GET', '/url');
+ expect(() {
+ hb('GET', '/url', null, callback);
+ }).toThrow('No response defined !');
+ });
- expect(hb('JSONP', '/url1')).toBeNull();
- expect(hb('JSONP', '/url2')).toBeNull();
- });
+ it('should respond undefined when JSONP method', () {
+ hb.when('JSONP', '/url1').respond(200);
+ hb.expect('JSONP', '/url2').respond(200);
- describe('verifyExpectations', () {
+ expect(hb('JSONP', '/url1')).toBeNull();
+ expect(hb('JSONP', '/url2')).toBeNull();
+ });
+
+
+ describe('verifyExpectations', () {
- it('should throw exception if not all expectations were satisfied', () {
- hb.expect('POST', '/u1', 'ddd').respond(201, '', {});
- hb.expect('GET', '/u2').respond(200, '', {});
- hb.expect('POST', '/u3').respond(201, '', {});
+ it('should throw exception if not all expectations were satisfied', () {
+ hb.expect('POST', '/u1', 'ddd').respond(201, '', {});
+ hb.expect('GET', '/u2').respond(200, '', {});
+ hb.expect('POST', '/u3').respond(201, '', {});
- hb('POST', '/u1', 'ddd', noop, {});
+ hb('POST', '/u1', 'ddd', noop, {});
- expect(() {hb.verifyNoOutstandingExpectation();}).
+ expect(() {hb.verifyNoOutstandingExpectation();}).
toThrow('Unsatisfied requests: GET /u2, POST /u3');
- });
+ });
- it('should do nothing when no expectation', () {
- hb.when('DELETE', '/some').respond(200, '');
+ it('should do nothing when no expectation', () {
+ hb.when('DELETE', '/some').respond(200, '');
- expect(() {hb.verifyNoOutstandingExpectation();}).not.toThrow();
- });
+ expect(() {hb.verifyNoOutstandingExpectation();}).not.toThrow();
+ });
- it('should do nothing when all expectations satisfied', () {
- hb.expect('GET', '/u2').respond(200, '', {});
- hb.expect('POST', '/u3').respond(201, '', {});
- hb.when('DELETE', '/some').respond(200, '');
+ it('should do nothing when all expectations satisfied', () {
+ hb.expect('GET', '/u2').respond(200, '', {});
+ hb.expect('POST', '/u3').respond(201, '', {});
+ hb.when('DELETE', '/some').respond(200, '');
- hb('GET', '/u2');
- hb('POST', '/u3');
+ hb('GET', '/u2');
+ hb('POST', '/u3');
- expect(() {hb.verifyNoOutstandingExpectation();}).not.toThrow();
+ expect(() {hb.verifyNoOutstandingExpectation();}).not.toThrow();
+ });
});
- });
- describe('verifyRequests', () {
+ describe('verifyRequests', () {
- it('should throw exception if not all requests were flushed', () {
- hb.when('GET').respond(200);
- hb('GET', '/some', null, noop, {});
+ it('should throw exception if not all requests were flushed', () {
+ hb.when('GET').respond(200);
+ hb('GET', '/some', null, noop, {});
- expect(() {
- hb.verifyNoOutstandingRequest();
- }).toThrow('Unflushed requests: 1');
+ expect(() {
+ hb.verifyNoOutstandingRequest();
+ }).toThrow('Unflushed requests: 1');
+ });
});
- });
- describe('resetExpectations', () {
+ describe('resetExpectations', () {
- it('should remove all expectations', () {
- hb.expect('GET', '/u2').respond(200, '', {});
- hb.expect('POST', '/u3').respond(201, '', {});
- hb.resetExpectations();
+ it('should remove all expectations', () {
+ hb.expect('GET', '/u2').respond(200, '', {});
+ hb.expect('POST', '/u3').respond(201, '', {});
+ hb.resetExpectations();
- expect(() {hb.verifyNoOutstandingExpectation();}).not.toThrow();
- });
+ expect(() {hb.verifyNoOutstandingExpectation();}).not.toThrow();
+ });
- it('should remove all pending responses', () {
- var cancelledClb = jasmine.createSpy('cancelled');
+ it('should remove all pending responses', () {
+ var cancelledClb = jasmine.createSpy('cancelled');
- hb.expect('GET', '/url').respond(200, '');
- hb('GET', '/url', null, cancelledClb);
- hb.resetExpectations();
+ hb.expect('GET', '/url').respond(200, '');
+ hb('GET', '/url', null, cancelledClb);
+ hb.resetExpectations();
- hb.expect('GET', '/url').respond(300, '');
- hb('GET', '/url', null, callback, {});
- hb.flush();
+ hb.expect('GET', '/url').respond(300, '');
+ hb('GET', '/url', null, callback, {});
+ hb.flush();
- expect(callback).toHaveBeenCalledOnce();
- expect(cancelledClb).not.toHaveBeenCalled();
- });
+ expect(callback).toHaveBeenCalledOnce();
+ expect(cancelledClb).not.toHaveBeenCalled();
+ });
- it('should not remove definitions', () {
- var cancelledClb = jasmine.createSpy('cancelled');
+ it('should not remove definitions', () {
+ var cancelledClb = jasmine.createSpy('cancelled');
- hb.when('GET', '/url').respond(200, 'success');
- hb('GET', '/url', null, cancelledClb);
- hb.resetExpectations();
+ hb.when('GET', '/url').respond(200, 'success');
+ hb('GET', '/url', null, cancelledClb);
+ hb.resetExpectations();
- hb('GET', '/url', null, callback, {});
- hb.flush();
+ hb('GET', '/url', null, callback, {});
+ hb.flush();
- expect(callback).toHaveBeenCalledOnce();
- expect(cancelledClb).not.toHaveBeenCalled();
+ expect(callback).toHaveBeenCalledOnce();
+ expect(cancelledClb).not.toHaveBeenCalled();
+ });
});
- });
- describe('expect/when shortcuts', () {
- [[(x) => hb.expectGET(x), 'GET'],
- [(x) => hb.expectPOST(x), 'POST'],
- [(x) => hb.expectPUT(x), 'PUT'],
- [(x) => hb.expectPATCH(x), 'PATCH'],
- [(x) => hb.expectDELETE(x), 'DELETE'],
- [(x) => hb.expectJSONP(x), 'JSONP'],
- [(x) => hb.whenGET(x), 'GET'],
- [(x) => hb.whenPOST(x), 'POST'],
- [(x) => hb.whenPUT(x), 'PUT'],
- [(x) => hb.whenPATCH(x), 'PATCH'],
- [(x) => hb.whenDELETE(x), 'DELETE'],
- [(x) => hb.whenJSONP(x), 'JSONP']
- ].forEach((step) {
+ describe('expect/when shortcuts', () {
+ [[(x) => hb.expectGET(x), 'GET'],
+ [(x) => hb.expectPOST(x), 'POST'],
+ [(x) => hb.expectPUT(x), 'PUT'],
+ [(x) => hb.expectPATCH(x), 'PATCH'],
+ [(x) => hb.expectDELETE(x), 'DELETE'],
+ [(x) => hb.expectJSONP(x), 'JSONP'],
+ [(x) => hb.whenGET(x), 'GET'],
+ [(x) => hb.whenPOST(x), 'POST'],
+ [(x) => hb.whenPUT(x), 'PUT'],
+ [(x) => hb.whenPATCH(x), 'PATCH'],
+ [(x) => hb.whenDELETE(x), 'DELETE'],
+ [(x) => hb.whenJSONP(x), 'JSONP']
+ ].forEach((step) {
var shortcut = step[0], method = step[1];
it('should provide $shortcut shortcut method', () {
shortcut('/foo').respond('bar');
@@ -481,37 +482,38 @@ main() => describe('MockHttpBackend', () {
expect(callback).toHaveBeenCalledOnceWith(200, 'bar', '');
});
});
- });
+ });
- describe('MockHttpExpectation', () {
+ describe('MockHttpExpectation', () {
- it('should accept url as regexp', () {
- var exp = new MockHttpExpectation('GET', new RegExp('^\/x'));
+ it('should accept url as regexp', () {
+ var exp = new MockHttpExpectation('GET', new RegExp('^\/x'));
- expect(exp.match('GET', '/x')).toBe(true);
- expect(exp.match('GET', '/xxx/x')).toBe(true);
- expect(exp.match('GET', 'x')).toBe(false);
- expect(exp.match('GET', 'a/x')).toBe(false);
- });
+ expect(exp.match('GET', '/x')).toBe(true);
+ expect(exp.match('GET', '/xxx/x')).toBe(true);
+ expect(exp.match('GET', 'x')).toBe(false);
+ expect(exp.match('GET', 'a/x')).toBe(false);
+ });
- it('should accept data as regexp', () {
- var exp = new MockHttpExpectation('POST', '/url', new RegExp('\{.*?\}'));
+ it('should accept data as regexp', () {
+ var exp = new MockHttpExpectation('POST', '/url', new RegExp('\{.*?\}'));
- expect(exp.match('POST', '/url', '{"a": "aa"}')).toBe(true);
- expect(exp.match('POST', '/url', '{"one": "two"}')).toBe(true);
- expect(exp.match('POST', '/url', '{"one"')).toBe(false);
- });
+ expect(exp.match('POST', '/url', '{"a": "aa"}')).toBe(true);
+ expect(exp.match('POST', '/url', '{"one": "two"}')).toBe(true);
+ expect(exp.match('POST', '/url', '{"one"')).toBe(false);
+ });
- it('should accept headers as function', () {
- var exp = new MockHttpExpectation('GET', '/url', undefined, (h) {
- return h['Content-Type'] == 'application/json';
- });
+ it('should accept headers as function', () {
+ var exp = new MockHttpExpectation('GET', '/url', undefined, (h) {
+ return h['Content-Type'] == 'application/json';
+ });
- expect(exp.matchHeaders({})).toBe(false);
- expect(exp.matchHeaders({'Content-Type': 'application/json', 'X-Another': 'true'})).toBe(true);
+ expect(exp.matchHeaders({})).toBe(false);
+ expect(exp.matchHeaders({'Content-Type': 'application/json', 'X-Another': 'true'})).toBe(true);
+ });
});
});
-});
+}
« no previous file with comments | « third_party/pkg/angular/test/jasmines_syntax_spec.dart ('k') | third_party/pkg/angular/test/mock/test_bed_spec.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698