本文整理汇总了TypeScript中@angular/compiler/testing/src/resource_loader_mock.MockResourceLoader类的典型用法代码示例。如果您正苦于以下问题:TypeScript MockResourceLoader类的具体用法?TypeScript MockResourceLoader怎么用?TypeScript MockResourceLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MockResourceLoader类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: createSummaries
function createSummaries() {
const resourceLoader = new MockResourceLoader();
setMetadata(resourceLoader);
TestBed.configureCompiler({providers: [{provide: ResourceLoader, useValue: resourceLoader}]});
TestBed.configureTestingModule({imports: [SomeModule], providers: [SomeDep]});
let summariesPromise = TestBed.compileComponents().then(() => {
const metadataResolver = TestBed.get(CompileMetadataResolver) as CompileMetadataResolver;
const summaries = [
metadataResolver.getNgModuleSummary(SomeModule),
// test nesting via closures, as we use this in the generated code too.
() =>
[metadataResolver.getDirectiveSummary(SomePublicComponent),
metadataResolver.getDirectiveSummary(SomePrivateComponent),
],
metadataResolver.getDirectiveSummary(SomeDirective),
metadataResolver.getPipeSummary(SomePipe),
metadataResolver.getInjectableSummary(SomeService)
];
clearMetadata();
TestBed.resetTestingModule();
return () => summaries;
});
resourceLoader.flush();
return summariesPromise;
}
开发者ID:thorn0,项目名称:angular,代码行数:29,代码来源:jit_summaries_integration_spec.ts
示例2: setMetadata
function setMetadata(resourceLoader: MockResourceLoader) {
Base.parameters = [[SomeDep]];
SomeModule.annotations = [new NgModule({
declarations: [SomePublicComponent, SomePrivateComponent, SomeDirective, SomePipe],
exports: [SomeDirective, SomePipe, SomePublicComponent],
providers: [SomeService]
})];
SomePublicComponent.annotations = [new Component({templateUrl: 'somePublicUrl.html'})];
resourceLoader.expect('somePublicUrl.html', `Hello public world!`);
SomePrivateComponent.annotations = [new Component({templateUrl: 'somePrivateUrl.html'})];
resourceLoader.expect('somePrivateUrl.html', `Hello private world!`);
SomeDirective.annotations = [new Directive({selector: '[someDir]'})];
SomePipe.annotations = [new Pipe({name: 'somePipe'})];
SomeService.annotations = [new Injectable()];
}
开发者ID:thorn0,项目名称:angular,代码行数:21,代码来源:jit_summaries_integration_spec.ts
示例3: describe
describe('MockResourceLoader', () => {
let resourceLoader: MockResourceLoader;
beforeEach(() => { resourceLoader = new MockResourceLoader(); });
function expectResponse(
request: Promise<string>, url: string, response: string, done: () => void = null) {
function onResponse(text: string): string {
if (response === null) {
throw `Unexpected response ${url} -> ${text}`;
} else {
expect(text).toEqual(response);
if (done != null) done();
}
return text;
}
function onError(error: string): string {
if (response !== null) {
throw `Unexpected error ${url}`;
} else {
expect(error).toEqual(`Failed to load ${url}`);
if (done != null) done();
}
return error;
}
request.then(onResponse, onError);
}
it('should return a response from the definitions',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const url = '/foo';
const response = 'bar';
resourceLoader.when(url, response);
expectResponse(resourceLoader.get(url), url, response, () => async.done());
resourceLoader.flush();
}));
it('should return an error from the definitions',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const url = '/foo';
const response: string = null;
resourceLoader.when(url, response);
expectResponse(resourceLoader.get(url), url, response, () => async.done());
resourceLoader.flush();
}));
it('should return a response from the expectations',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const url = '/foo';
const response = 'bar';
resourceLoader.expect(url, response);
expectResponse(resourceLoader.get(url), url, response, () => async.done());
resourceLoader.flush();
}));
it('should return an error from the expectations',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const url = '/foo';
const response: string = null;
resourceLoader.expect(url, response);
expectResponse(resourceLoader.get(url), url, response, () => async.done());
resourceLoader.flush();
}));
it('should not reuse expectations', () => {
const url = '/foo';
const response = 'bar';
resourceLoader.expect(url, response);
resourceLoader.get(url);
resourceLoader.get(url);
expect(() => { resourceLoader.flush(); }).toThrowError('Unexpected request /foo');
});
it('should return expectations before definitions',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const url = '/foo';
resourceLoader.when(url, 'when');
resourceLoader.expect(url, 'expect');
expectResponse(resourceLoader.get(url), url, 'expect');
expectResponse(resourceLoader.get(url), url, 'when', () => async.done());
resourceLoader.flush();
}));
it('should throw when there is no definitions or expectations', () => {
resourceLoader.get('/foo');
expect(() => { resourceLoader.flush(); }).toThrowError('Unexpected request /foo');
});
it('should throw when flush is called without any pending requests', () => {
expect(() => { resourceLoader.flush(); }).toThrowError('No pending requests to flush');
});
it('should throw on unsatisfied expectations', () => {
resourceLoader.expect('/foo', 'bar');
resourceLoader.when('/bar', 'foo');
resourceLoader.get('/bar');
expect(() => { resourceLoader.flush(); }).toThrowError('Unsatisfied requests: /foo');
});
//.........这里部分代码省略.........
开发者ID:JohnnyQQQQ,项目名称:angular,代码行数:101,代码来源:resource_loader_mock_spec.ts
示例4: inject
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const url = '/foo';
const response: string = null;
resourceLoader.expect(url, response);
expectResponse(resourceLoader.get(url), url, response, () => async.done());
resourceLoader.flush();
}));
开发者ID:JohnnyQQQQ,项目名称:angular,代码行数:7,代码来源:resource_loader_mock_spec.ts
示例5: it
it('should not reuse expectations', () => {
const url = '/foo';
const response = 'bar';
resourceLoader.expect(url, response);
resourceLoader.get(url);
resourceLoader.get(url);
expect(() => { resourceLoader.flush(); }).toThrowError('Unexpected request /foo');
});
开发者ID:JohnnyQQQQ,项目名称:angular,代码行数:8,代码来源:resource_loader_mock_spec.ts
示例6: expect
expect(() => { resourceLoader.flush(); }).toThrowError('Unexpected request /foo');
开发者ID:JohnnyQQQQ,项目名称:angular,代码行数:1,代码来源:resource_loader_mock_spec.ts
注:本文中的@angular/compiler/testing/src/resource_loader_mock.MockResourceLoader类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论