refactor(platform-browser-dynamic): Removed TestComponentBuilder from ResourceLoaderCache specs (#10890)
This commit is contained in:
parent
39a2c39cef
commit
939d318242
|
@ -9,7 +9,7 @@
|
|||
import {ResourceLoader, UrlResolver} from '@angular/compiler';
|
||||
import {BaseException, Component} from '@angular/core';
|
||||
import {TestBed, fakeAsync, flushMicrotasks, tick} from '@angular/core/testing';
|
||||
import {AsyncTestCompleter, TestComponentBuilder, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
|
||||
import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
|
||||
import {expect} from '@angular/platform-browser/testing/matchers';
|
||||
|
||||
import {CachedResourceLoader} from '../../src/resource_loader/resource_loader_cache';
|
||||
|
@ -18,33 +18,36 @@ import {setTemplateCache} from './resource_loader_cache_setter';
|
|||
|
||||
export function main() {
|
||||
describe('CachedResourceLoader', () => {
|
||||
var xhr: CachedResourceLoader;
|
||||
var resourceLoader: CachedResourceLoader;
|
||||
|
||||
function createCachedResourceLoader(): CachedResourceLoader {
|
||||
setTemplateCache({'test.html': '<div>Hello</div>'});
|
||||
return new CachedResourceLoader();
|
||||
}
|
||||
beforeEach(() => {
|
||||
beforeEach(fakeAsync(() => {
|
||||
TestBed.configureCompiler({
|
||||
providers: [
|
||||
{provide: UrlResolver, useClass: TestUrlResolver},
|
||||
{provide: ResourceLoader, useFactory: createCachedResourceLoader}
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
TestBed.configureTestingModule({declarations: [TestComponent]});
|
||||
TestBed.compileComponents();
|
||||
}));
|
||||
|
||||
it('should throw exception if $templateCache is not found', () => {
|
||||
setTemplateCache(null);
|
||||
expect(() => {
|
||||
xhr = new CachedResourceLoader();
|
||||
resourceLoader = new CachedResourceLoader();
|
||||
}).toThrowError('CachedResourceLoader: Template cache was not found in $templateCache.');
|
||||
});
|
||||
|
||||
it('should resolve the Promise with the cached file content on success',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
setTemplateCache({'test.html': '<div>Hello</div>'});
|
||||
xhr = new CachedResourceLoader();
|
||||
xhr.get('test.html').then((text) => {
|
||||
resourceLoader = new CachedResourceLoader();
|
||||
resourceLoader.get('test.html').then((text) => {
|
||||
expect(text).toEqual('<div>Hello</div>');
|
||||
async.done();
|
||||
});
|
||||
|
@ -52,21 +55,18 @@ export function main() {
|
|||
|
||||
it('should reject the Promise on failure',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
xhr = new CachedResourceLoader();
|
||||
xhr.get('unknown.html')
|
||||
resourceLoader = new CachedResourceLoader();
|
||||
resourceLoader.get('unknown.html')
|
||||
.then((text) => { throw new BaseException('Not expected to succeed.'); })
|
||||
.catch((error) => { async.done(); });
|
||||
}));
|
||||
|
||||
it('should allow fakeAsync Tests to load components with templateUrl synchronously',
|
||||
fakeAsync(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||
let fixture = tcb.createFakeAsync(TestComponent);
|
||||
|
||||
// This should initialize the fixture.
|
||||
tick();
|
||||
|
||||
fakeAsync(() => {
|
||||
let fixture = TestBed.createComponent(TestComponent);
|
||||
fixture.detectChanges();
|
||||
expect(fixture.debugElement.children[0].nativeElement).toHaveText('Hello');
|
||||
})));
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue