diff --git a/karma-dart.conf.js b/karma-dart.conf.js index a9c5928246..d7e21b3d5a 100644 --- a/karma-dart.conf.js +++ b/karma-dart.conf.js @@ -19,7 +19,8 @@ module.exports = function(config) { {pattern: 'packages/**/*.dart', included: false, watched: false}, // Init and configure guiness. - {pattern: 'test-main.dart', included: true} + {pattern: 'test-main.dart', included: true}, + {pattern: 'modules/**/test/**/static_assets/**', included: false, watched: false}, ], exclude: [ diff --git a/karma-js.conf.js b/karma-js.conf.js index b94f672cfc..8549550b83 100644 --- a/karma-js.conf.js +++ b/karma-js.conf.js @@ -23,7 +23,8 @@ module.exports = function(config) { 'node_modules/rx/dist/rx.js', 'node_modules/reflect-metadata/Reflect.js', 'tools/build/file2modulename.js', - 'test-main.js' + 'test-main.js', + {pattern: 'modules/**/test/**/static_assets/**', included: false, watched: false} ], exclude: [ diff --git a/modules/angular2/src/services/xhr_impl.dart b/modules/angular2/src/services/xhr_impl.dart index b5feb06b75..91ce87dea6 100644 --- a/modules/angular2/src/services/xhr_impl.dart +++ b/modules/angular2/src/services/xhr_impl.dart @@ -1,15 +1,17 @@ library angular2.src.services.xhr_impl; -import 'dart:async'; -import 'dart:html'; +import 'dart:async' show Future; +import 'dart:html' show HttpRequest; import 'package:angular2/di.dart'; import './xhr.dart' show XHR; @Injectable() class XHRImpl extends XHR { Future get(String url) { - return HttpRequest.request(url).then( - (HttpRequest request) => request.responseText, - onError: (Error e) => throw 'Failed to load $url'); + + return HttpRequest + .request(url) + .then((HttpRequest req) => req.responseText, + onError: (_) => new Future.error('Failed to load $url')); } } diff --git a/modules/angular2/src/services/xhr_impl.ts b/modules/angular2/src/services/xhr_impl.ts index 433e4d45c0..71b61f2451 100644 --- a/modules/angular2/src/services/xhr_impl.ts +++ b/modules/angular2/src/services/xhr_impl.ts @@ -15,11 +15,11 @@ export class XHRImpl extends XHR { if (200 <= status && status <= 300) { completer.resolve(xhr.responseText); } else { - completer.reject(`Failed to load ${url}`); + completer.reject(`Failed to load ${url}`, null); } }; - xhr.onerror = function() { completer.reject(`Failed to load ${url}`); }; + xhr.onerror = function() { completer.reject(`Failed to load ${url}`, null); }; xhr.send(); return completer.promise; diff --git a/modules/angular2/test/services/static_assets/200.html b/modules/angular2/test/services/static_assets/200.html new file mode 100644 index 0000000000..28f5df8830 --- /dev/null +++ b/modules/angular2/test/services/static_assets/200.html @@ -0,0 +1 @@ +

hey

diff --git a/modules/angular2/test/services/xhr_impl_spec.js b/modules/angular2/test/services/xhr_impl_spec.js new file mode 100644 index 0000000000..f0abb58527 --- /dev/null +++ b/modules/angular2/test/services/xhr_impl_spec.js @@ -0,0 +1,43 @@ +import { + AsyncTestCompleter, + beforeEach, + ddescribe, + describe, + expect, + iit, + inject, + it, + xit +} from 'angular2/test_lib'; + +import {XHRImpl} from 'angular2/src/services/xhr_impl'; +import {PromiseWrapper} from 'angular2/src/facade/async'; + +export function main() { + describe('XHRImpl', () => { + var xhr; + var url200 = '/base/modules/angular2/test/services/static_assets/200.html'; + var url404 = '/base/modules/angular2/test/services/static_assets/404.html'; + + beforeEach(() => { + xhr = new XHRImpl(); + }); + + it('should resolve the Promise with the file content on success', inject([AsyncTestCompleter], (async) => { + xhr.get(url200).then((text) => { + expect(text.trim()).toEqual('

hey

'); + async.done(); + }); + })); + + it('should reject the Promise on failure', inject([AsyncTestCompleter], (async) => { + PromiseWrapper.catchError( + xhr.get(url404), + (e) => { + expect(e).toEqual(`Failed to load ${url404}`); + async.done(); + } + ); + })); + }); +} diff --git a/tools/broccoli/trees/node_tree.ts b/tools/broccoli/trees/node_tree.ts index 8fb8f85c14..8a1f1b4cdf 100644 --- a/tools/broccoli/trees/node_tree.ts +++ b/tools/broccoli/trees/node_tree.ts @@ -22,7 +22,8 @@ module.exports = function makeNodeTree(destinationPath) { exclude: [ // the following code and tests are not compatible with CJS/node environment 'angular2/test/core/zone/**', - 'angular2/test/test_lib/fake_async_spec.js' + 'angular2/test/test_lib/fake_async_spec.js', + 'angular2/test/services/xhr_impl_spec.js' ] });