2016-06-08 19:38:52 -04:00
|
|
|
import {AsyncTestCompleter, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
|
|
|
|
|
2016-04-28 20:50:03 -04:00
|
|
|
import {PromiseWrapper} from '../../src/facade/async';
|
2016-06-08 19:38:52 -04:00
|
|
|
import {XHRImpl} from '../../src/xhr/xhr_impl';
|
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-05-20 19:11:49 -04:00
|
|
|
var url200 = '/base/modules/@angular/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',
|
2016-06-09 14:04:15 -04:00
|
|
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
2015-05-27 16:48:24 -04:00
|
|
|
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
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
it('should reject the Promise on failure',
|
|
|
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
2015-05-27 16:48:24 -04:00
|
|
|
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
|
|
|
});
|
|
|
|
}
|