本文整理汇总了TypeScript中@angular/compiler/testing.TestComponentBuilder类的典型用法代码示例。如果您正苦于以下问题:TypeScript TestComponentBuilder类的具体用法?TypeScript TestComponentBuilder怎么用?TypeScript TestComponentBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestComponentBuilder类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('Component: Button', () => {
let builder: TestComponentBuilder;
beforeEachProviders(() => [SoundBlip]);
beforeEach(inject([TestComponentBuilder],
function(tcb: TestComponentBuilder) {
builder = tcb;
})
);
it('should invoke onClick when clicked',
async(inject([], () => {
return builder.createAsync(SoundBlip)
.then((fixture: ComponentFixture<any>) => {
spyOn(fixture.componentInstance, 'onClick');
fixture.componentInstance.qaid = 'button-1';
fixture.detectChanges();
let compiled = fixture.debugElement.nativeElement;
compiled.querySelector('#button-1').click();
expect(fixture.componentInstance.handleClick).toHaveBeenCalled();
});
}))
);
});
示例2: expect
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
var template = '<div>' +
'<ul [ngSwitch]="switchValue">' +
'<template ngSwitchWhen="a"><li>when a</li></template>' +
'<template ngSwitchWhen="b"><li>when b</li></template>' +
'</ul></div>';
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((fixture) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('');
fixture.debugElement.componentInstance.switchValue = 'a';
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('when a');
fixture.debugElement.componentInstance.switchValue = 'b';
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('when b');
async.done();
});
}));
示例3: describe
describe('Component: Home', () => {
let builder: TestComponentBuilder;
beforeEachProviders(() => [
HomeComponent,
TD_LAYOUT_PROVIDERS,
]);
beforeEach(inject([TestComponentBuilder], function (tcb: TestComponentBuilder): void {
builder = tcb;
}));
it('should inject the component', inject([HomeComponent], (component: HomeComponent) => {
expect(component).toBeTruthy();
}));
it('should create the component', inject([], () => {
return builder.createAsync(HomeTestControllerComponent)
.then((fixture: ComponentFixture<any>) => {
let query: DebugElement = fixture.debugElement.query(By.directive(HomeComponent));
expect(query).toBeTruthy();
expect(query.componentInstance).toBeTruthy();
});
}));
});
示例4: inject
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: any /** TODO #9100 */) => {
var html = '<div><copy-me template="ngIf numberCondition">hello</copy-me></div>';
tcb.overrideTemplate(TestComponent, html)
.createAsync(TestComponent)
.then((fixture) => {
fixture.detectChanges();
expect(getDOM()
.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me')
.length)
.toEqual(1);
expect(fixture.debugElement.nativeElement).toHaveText('hello');
fixture.debugElement.componentInstance.numberCondition = 2;
fixture.detectChanges();
expect(getDOM()
.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me')
.length)
.toEqual(1);
expect(fixture.debugElement.nativeElement).toHaveText('hello');
async.done();
});
}));
示例5: inject
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: any /** TODO #9100 */) => {
var template = `<div [ngStyle]="expr"></div>`;
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((fixture) => {
var expr: Map<string, any>;
fixture.debugElement.componentInstance.expr = {'max-width': '40px'};
fixture.detectChanges();
expect(
getDOM().getStyle(fixture.debugElement.children[0].nativeElement, 'max-width'))
.toEqual('40px');
expr = fixture.debugElement.componentInstance.expr;
(expr as any /** TODO #9100 */)['max-width'] = '30%';
fixture.detectChanges();
expect(
getDOM().getStyle(fixture.debugElement.children[0].nativeElement, 'max-width'))
.toEqual('30%');
async.done();
});
}));
示例6: advance
(tcb: TestComponentBuilder, location: Location, angulartics2: Angulartics2, angulartics2Piwik: Angulartics2Piwik) => {
fixture = tcb.createFakeAsync(RootCmp);
angulartics2.setUserProperties.next({ userId: '1', firstName: 'John', lastName: 'Doe' });
advance(fixture);
expect(_paq).toContain(['setCustomVariable', { userId: '1', firstName: 'John', lastName: 'Doe' }]);
})));
示例7:
const compile = (tcb: TestComponentBuilder, template: string = '') => {
return tcb
.overrideTemplate(TestComponent, template)
.createAsync(TestComponent);
};