Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions modules/angular2/src/http/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ export class Http {
new Request(mergeOptions(this._defaultOptions, options, RequestMethods.Get, url)));
} else if (url instanceof Request) {
responseObservable = httpRequest(this._backend, url);
} else {
throw makeTypeError('First argument must be a url string or Request instance.');
}
return responseObservable;
}
Expand Down Expand Up @@ -201,6 +203,8 @@ export class Jsonp extends Http {
makeTypeError('JSONP requests must use GET request method.');
}
responseObservable = httpRequest(this._backend, url);
} else {
throw makeTypeError('First argument must be a url string or Request instance.');
}
return responseObservable;
}
Expand Down
24 changes: 24 additions & 0 deletions modules/angular2/test/http/http_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export function main() {
var injector: Injector;
var backend: MockBackend;
var baseResponse;
var jsonp: Jsonp;
beforeEach(() => {
injector = Injector.resolveAndCreate([
BaseRequestOptions,
Expand All @@ -111,9 +112,15 @@ export function main() {
function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
return new Http(backend, defaultOptions);
},
[MockBackend, BaseRequestOptions]),
bind(Jsonp).toFactory(
function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
return new Jsonp(backend, defaultOptions);
},
[MockBackend, BaseRequestOptions])
]);
http = injector.get(Http);
jsonp = injector.get(Jsonp);
backend = injector.get(MockBackend);
baseResponse = new Response(new ResponseOptions({body: 'base response'}));
});
Expand Down Expand Up @@ -160,6 +167,13 @@ export function main() {
// async.done();
// });
// }));


it('should throw if url is not a string or Request', () => {
var req = <Request>{};
expect(() => http.request(req))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised we don't have a Jsonp unit test for this method! Could you just duplicate this expectation in the same spec and call jsonp.request?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, will do.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a new describe block for Jsonp, along with this same expectation for jsonp.

.toThrowError('First argument must be a url string or Request instance.');
});
});


Expand Down Expand Up @@ -306,5 +320,15 @@ export function main() {
}));
});
});

describe('Jsonp', () => {
describe('.request()', () => {
it('should throw if url is not a string or Request', () => {
var req = <Request>{};
expect(() => jsonp.request(req))
.toThrowError('First argument must be a url string or Request instance.');
});
});
});
});
}