本文整理汇总了TypeScript中angular2/testing_internal.inject函数的典型用法代码示例。如果您正苦于以下问题:TypeScript inject函数的具体用法?TypeScript inject怎么用?TypeScript inject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了inject函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('getViewDirectivesMetadata', () => {
it('should return the directive metadatas',
inject([RuntimeMetadataResolver], (resolver: RuntimeMetadataResolver) => {
expect(resolver.getViewDirectivesMetadata(ComponentWithEverything))
.toContain(resolver.getDirectiveMetadata(SomeDirective));
}));
describe("platform directives", () => {
beforeEachProviders(
() => [provide(PLATFORM_DIRECTIVES, {useValue: [ADirective], multi: true})]);
it('should include platform directives when available',
inject([RuntimeMetadataResolver], (resolver: RuntimeMetadataResolver) => {
expect(resolver.getViewDirectivesMetadata(ComponentWithEverything))
.toContain(resolver.getDirectiveMetadata(ADirective));
expect(resolver.getViewDirectivesMetadata(ComponentWithEverything))
.toContain(resolver.getDirectiveMetadata(SomeDirective));
}));
});
});
开发者ID:1186792881,项目名称:angular,代码行数:21,代码来源:runtime_metadata_spec.ts
示例2: describe
describe('hierarchical app', () => {
beforeEachProviders(
() => { return [provide(ROUTER_PRIMARY_COMPONENT, {useValue: HierarchyAppCmp})]; });
it('should bootstrap an app with a hierarchy',
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
tcb.createAsync(HierarchyAppCmp).then((fixture) => {
var router = fixture.debugElement.componentInstance.router;
router.subscribe((_) => {
expect(fixture.debugElement.nativeElement).toHaveText('root { parent { hello } }');
expect(fixture.debugElement.componentInstance.location.path())
.toEqual('/parent/child');
async.done();
});
router.navigateByUrl('/parent/child');
});
}));
// TODO(btford): mock out level lower than LocationStrategy once that level exists
xdescribe('custom app base ref', () => {
beforeEachProviders(() => { return [provide(APP_BASE_HREF, {useValue: '/my/app'})]; });
it('should bootstrap',
inject(
[AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
tcb.createAsync(HierarchyAppCmp).then((fixture) => {
var router = fixture.debugElement.componentInstance.router;
router.subscribe((_) => {
expect(fixture.debugElement.nativeElement)
.toHaveText('root { parent { hello } }');
expect(fixture.debugElement.componentInstance.location.path())
.toEqual('/my/app/parent/child');
async.done();
});
router.navigateByUrl('/parent/child');
});
}));
});
});
开发者ID:LordBinary,项目名称:angular,代码行数:40,代码来源:bootstrap_spec.ts
示例3: describe
describe('when values changes', () => {
it('should switch amongst when values',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var template = '<div>' +
'<ul [ngSwitch]="switchValue">' +
'<template [ngSwitchWhen]="when1"><li>when 1;</li></template>' +
'<template [ngSwitchWhen]="when2"><li>when 2;</li></template>' +
'<template ngSwitchDefault><li>when default;</li></template>' +
'</ul></div>';
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((fixture) => {
fixture.debugElement.componentInstance.when1 = 'a';
fixture.debugElement.componentInstance.when2 = 'b';
fixture.debugElement.componentInstance.switchValue = 'a';
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('when 1;');
fixture.debugElement.componentInstance.switchValue = 'b';
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('when 2;');
fixture.debugElement.componentInstance.switchValue = 'c';
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('when default;');
fixture.debugElement.componentInstance.when1 = 'c';
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('when 1;');
fixture.debugElement.componentInstance.when1 = 'd';
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('when default;');
async.done();
});
}));
});
开发者ID:LordBinary,项目名称:angular,代码行数:39,代码来源:ng_switch_spec.ts
示例4: describe
describe('compileComponentCodeGen', () => {
function detectChanges(
compiler: ChangeDetectionCompiler, template: string,
directives: CompileDirectiveMetadata[] = CONST_EXPR([])): Promise<string[]> {
var type =
new CompileTypeMetadata({name: stringify(SomeComponent), moduleUrl: THIS_MODULE_URL});
var parsedTemplate = parser.parse(template, directives, 'TestComp');
var sourceExpressions =
compiler.compileComponentCodeGen(type, ChangeDetectionStrategy.Default, parsedTemplate);
var testableModule = createTestableModule(sourceExpressions, 0).getSourceWithImports();
return evalModule(testableModule.source, testableModule.imports, null);
}
it('should watch element properties', inject([AsyncTestCompleter], (async) => {
detectChanges(compiler, '<div [elProp]="someProp">')
.then((value) => {
expect(value).toEqual(['elementProperty(elProp)=someValue']);
async.done();
});
}));
});
开发者ID:mixed,项目名称:angular,代码行数:22,代码来源:change_detector_compiler_spec.ts
示例5: describe
describe("WebWorkerXHRImpl", () => {
it("should pass requests through the broker and return the response",
inject([AsyncTestCompleter], (async) => {
const URL = "http://www.example.com/test";
const RESPONSE = "Example response text";
var messageBroker: any = new SpyMessageBroker();
messageBroker.spy("runOnService")
.andCallFake((args: UiArguments, returnType: Type) => {
expect(args.method).toEqual("get");
expect(args.args.length).toEqual(1);
expect(args.args[0].value).toEqual(URL);
return PromiseWrapper.wrap(() => { return RESPONSE; });
});
var xhrImpl = new WebWorkerXHRImpl(new MockMessageBrokerFactory(messageBroker));
xhrImpl.get(URL).then((response) => {
expect(response).toEqual(RESPONSE);
async.done();
});
}));
});
开发者ID:bet4vlom,项目名称:angular,代码行数:22,代码来源:xhr_impl_spec.ts
示例6: describe
describe("#all", () => {
it("should combine lists of Promises", inject([AsyncTestCompleter], (async) => {
var one = PromiseWrapper.completer();
var two = PromiseWrapper.completer();
var all = PromiseWrapper.all([one.promise, two.promise]);
var allCalled = false;
PromiseWrapper.then(one.promise, (_) => {
expect(allCalled).toBe(false);
two.resolve('two');
return null;
});
PromiseWrapper.then(all, (_) => {
allCalled = true;
async.done();
return null;
});
one.resolve('one');
}));
[null, true, false, 10, 'thing', {}, []].forEach(abruptCompletion => {
it(`should treat "${abruptCompletion}" as an "abrupt completion"`,
inject([AsyncTestCompleter], (async) => {
var one = PromiseWrapper.completer();
var all = PromiseWrapper.all([one.promise, abruptCompletion]);
PromiseWrapper.then(all, (val) => {
expect(val[1]).toEqual(abruptCompletion);
async.done();
});
one.resolve('one');
}));
});
});
开发者ID:1186792881,项目名称:angular,代码行数:39,代码来源:async_spec.ts
示例7: describe
describe('bootstrap functionality', () => {
it('should bootstrap a simple app', inject([AsyncTestCompleter], (async) => {
var fakeDoc = DOM.createHtmlDocument();
var el = DOM.createElement('app-cmp', fakeDoc);
DOM.appendChild(fakeDoc.body, el);
bootstrap(AppCmp,
[
ROUTER_PROVIDERS,
provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppCmp}),
provide(LocationStrategy, {useClass: MockLocationStrategy}),
provide(DOCUMENT, {useValue: fakeDoc})
])
.then((applicationRef) => {
var router = applicationRef.hostComponent.router;
router.subscribe((_) => {
expect(el).toHaveText('outer { hello }');
expect(applicationRef.hostComponent.location.path()).toEqual('');
async.done();
});
});
}));
});
开发者ID:,项目名称:,代码行数:23,代码来源:
示例8: describe
describe('without APP_BASE_HREF', () => {
beforeEach(inject([PlatformLocation, HashLocationStrategy], (pl, ls) => {
platformLocation = pl;
locationStrategy = ls;
platformLocation.spy('pushState');
platformLocation.pathname = '';
}));
it('should prepend urls with a hash for non-empty URLs', () => {
expect(locationStrategy.prepareExternalUrl('foo')).toEqual('#foo');
locationStrategy.pushState(null, 'Title', 'foo', '');
expect(platformLocation.spy('pushState')).toHaveBeenCalledWith(null, 'Title', '#foo');
});
it('should prepend urls with a hash for URLs with query params', () => {
expect(locationStrategy.prepareExternalUrl('foo?bar')).toEqual('#foo?bar');
locationStrategy.pushState(null, 'Title', 'foo', 'bar=baz');
expect(platformLocation.spy('pushState'))
.toHaveBeenCalledWith(null, 'Title', '#foo?bar=baz');
});
it('should prepend urls with a hash for URLs with just query params', () => {
expect(locationStrategy.prepareExternalUrl('?bar')).toEqual('#?bar');
locationStrategy.pushState(null, 'Title', '', 'bar=baz');
expect(platformLocation.spy('pushState')).toHaveBeenCalledWith(null, 'Title', '#?bar=baz');
});
it('should not prepend a hash to external urls for an empty internal URL', () => {
expect(locationStrategy.prepareExternalUrl('')).toEqual('');
locationStrategy.pushState(null, 'Title', '', '');
expect(platformLocation.spy('pushState')).toHaveBeenCalledWith(null, 'Title', '');
});
});
开发者ID:844496869,项目名称:angular,代码行数:37,代码来源:hash_location_strategy_spec.ts
示例9: describe
describe('preparseElement', () => {
var htmlParser;
beforeEach(inject([HtmlParser], (_htmlParser: HtmlParser) => { htmlParser = _htmlParser; }));
function preparse(html: string): PreparsedElement {
return preparseElement(htmlParser.parse(html, 'TestComp').rootNodes[0]);
}
it('should detect script elements', inject([HtmlParser], (htmlParser: HtmlParser) => {
expect(preparse('<script>').type).toBe(PreparsedElementType.SCRIPT);
}));
it('should detect style elements', inject([HtmlParser], (htmlParser: HtmlParser) => {
expect(preparse('<style>').type).toBe(PreparsedElementType.STYLE);
}));
it('should detect stylesheet elements', inject([HtmlParser], (htmlParser: HtmlParser) => {
expect(preparse('<link rel="stylesheet">').type).toBe(PreparsedElementType.STYLESHEET);
expect(preparse('<link rel="stylesheet" href="someUrl">').hrefAttr).toEqual('someUrl');
expect(preparse('<link rel="someRel">').type).toBe(PreparsedElementType.OTHER);
}));
it('should detect ng-content elements', inject([HtmlParser], (htmlParser: HtmlParser) => {
expect(preparse('<ng-content>').type).toBe(PreparsedElementType.NG_CONTENT);
}));
it('should normalize ng-content.select attribute',
inject([HtmlParser], (htmlParser: HtmlParser) => {
expect(preparse('<ng-content>').selectAttr).toEqual('*');
expect(preparse('<ng-content select>').selectAttr).toEqual('*');
expect(preparse('<ng-content select="*">').selectAttr).toEqual('*');
}));
it('should extract ngProjectAs value', () => {
expect(preparse('<p ngProjectAs="el[attr].class"></p>').projectAs).toEqual('el[attr].class');
});
});
开发者ID:1186792881,项目名称:angular,代码行数:37,代码来源:template_preparser_spec.ts
注:本文中的angular2/testing_internal.inject函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论