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