2016-04-12 12:40:37 -04:00
|
|
|
import {
|
|
|
|
beforeEach,
|
|
|
|
ddescribe,
|
|
|
|
describe,
|
|
|
|
expect,
|
|
|
|
iit,
|
|
|
|
inject,
|
|
|
|
it,
|
2016-05-19 17:31:21 -04:00
|
|
|
xit,
|
|
|
|
AsyncTestCompleter
|
2016-04-28 20:50:03 -04:00
|
|
|
} from '@angular/core/testing/testing_internal';
|
|
|
|
import {XHRImpl} from '../../src/xhr/xhr_impl';
|
|
|
|
import {PromiseWrapper} from '../../src/facade/async';
|
|
|
|
import {IS_DART} from '../../src/facade/lang';
|
2015-05-27 16:48:24 -04:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('XHRImpl', () => {
|
2015-06-11 21:50:41 -04:00
|
|
|
var xhr: XHRImpl;
|
2016-02-10 19:54:32 -05:00
|
|
|
|
|
|
|
// TODO(juliemr): This file currently won't work with dart unit tests run using
|
|
|
|
// exclusive it or describe (iit or ddescribe). This is because when
|
|
|
|
// pub run test is executed against this specific file the relative paths
|
|
|
|
// will be relative to here, so url200 should look like
|
|
|
|
// static_assets/200.html.
|
|
|
|
// We currently have no way of detecting this.
|
2016-04-28 20:50:03 -04:00
|
|
|
var urlBase = IS_DART ? '' : '/base/modules/@angular/';
|
2016-05-19 17:31:21 -04:00
|
|
|
var url200 = urlBase + 'platform-browser/test/browser/static_assets/200.html';
|
2016-02-10 19:54:32 -05:00
|
|
|
var url404 = '/bad/path/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
|
|
|
});
|
|
|
|
}
|