2015-05-27 16:48:24 -04:00
|
|
|
import {
|
|
|
|
AsyncTestCompleter,
|
|
|
|
beforeEach,
|
|
|
|
ddescribe,
|
|
|
|
describe,
|
|
|
|
expect,
|
|
|
|
iit,
|
|
|
|
inject,
|
|
|
|
it,
|
|
|
|
xit
|
2015-10-13 03:29:13 -04:00
|
|
|
} from 'angular2/testing_internal';
|
2015-05-27 16:48:24 -04:00
|
|
|
|
2015-11-13 14:21:16 -05:00
|
|
|
import {XHRImpl} from 'angular2/src/platform/browser/xhr_impl';
|
2015-11-06 20:34:07 -05:00
|
|
|
import {PromiseWrapper} from 'angular2/src/facade/async';
|
2015-05-27 16:48:24 -04:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('XHRImpl', () => {
|
2015-06-11 21:50:41 -04:00
|
|
|
var xhr: XHRImpl;
|
2015-11-17 18:24:36 -05:00
|
|
|
var url200 = '/base/modules/angular2/test/platform/browser/static_assets/200.html';
|
|
|
|
var url404 = '/base/modules/angular2/test/platform/browser/static_assets/404.html';
|
2015-05-27 16:48:24 -04:00
|
|
|
|
|
|
|
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('<p>hey</p>');
|
|
|
|
async.done();
|
|
|
|
});
|
2015-06-02 10:29:09 -04:00
|
|
|
}), 10000);
|
2015-05-27 16:48:24 -04:00
|
|
|
|
|
|
|
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();
|
2015-06-11 21:50:41 -04:00
|
|
|
return null;
|
2015-05-27 16:48:24 -04:00
|
|
|
});
|
2015-06-02 10:29:09 -04:00
|
|
|
}), 10000);
|
2015-05-27 16:48:24 -04:00
|
|
|
});
|
|
|
|
}
|