本文整理匯總了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);
};