本文整理汇总了TypeScript中angular2/test_lib.TestComponentBuilder类的典型用法代码示例。如果您正苦于以下问题:TypeScript TestComponentBuilder类的具体用法?TypeScript TestComponentBuilder怎么用?TypeScript TestComponentBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestComponentBuilder类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: inject
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var html =
'<div><template [ng-if]="booleanCondition"><copy-me *ng-if="nestedBooleanCondition">hello</copy-me></template></div>';
tcb.overrideTemplate(TestComponent, html)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.componentInstance.booleanCondition = false;
rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.nativeElement, 'copy-me').length).toEqual(0);
expect(rootTC.nativeElement).toHaveText('');
rootTC.componentInstance.booleanCondition = true;
rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.nativeElement, 'copy-me').length).toEqual(1);
expect(rootTC.nativeElement).toHaveText('hello');
rootTC.componentInstance.nestedBooleanCondition = false;
rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.nativeElement, 'copy-me').length).toEqual(0);
expect(rootTC.nativeElement).toHaveText('');
rootTC.componentInstance.nestedBooleanCondition = true;
rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.nativeElement, 'copy-me').length).toEqual(1);
expect(rootTC.nativeElement).toHaveText('hello');
rootTC.componentInstance.booleanCondition = false;
rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.nativeElement, 'copy-me').length).toEqual(0);
expect(rootTC.nativeElement).toHaveText('');
async.done();
});
}));
示例2: inject
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideTemplate(TestComponent, '<div><todo></todo></div>')
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.detectChanges();
let todoInstance = rootTC.debugElement.componentViewChildren[0].componentInstance;
let aboutDOMEl = rootTC.debugElement.componentViewChildren[0].nativeElement;
var todosListLen = function () {
return todoInstance.todoService.get().length;
};
expect(todosListLen()).toEqual(2);
expect(DOM.querySelectorAll(aboutDOMEl, 'li').length).toEqual(todosListLen());
todoInstance.add({value: 'Test'});
rootTC.detectChanges();
expect(todosListLen()).toEqual(3);
expect(DOM.querySelectorAll(aboutDOMEl, 'li').length).toEqual(todosListLen());
expect(DOM.querySelectorAll(aboutDOMEl, 'li')[2].textContent).toContain('Test');
async.done();
});
}));
示例3: inject
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var template = '<div>' +
'<ul [ng-switch]="switchValue">' +
'<template ng-switch-when="a"><li>when a1;</li></template>' +
'<template ng-switch-when="b"><li>when b1;</li></template>' +
'<template ng-switch-when="a"><li>when a2;</li></template>' +
'<template ng-switch-when="b"><li>when b2;</li></template>' +
'<template ng-switch-default><li>when default1;</li></template>' +
'<template ng-switch-default><li>when default2;</li></template>' +
'</ul></div>';
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('when default1;when default2;');
rootTC.componentInstance.switchValue = 'a';
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('when a1;when a2;');
rootTC.componentInstance.switchValue = 'b';
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('when b1;when b2;');
async.done();
});
}));
示例4: inject
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideTemplate(TestComponent, '<div><offers></offers></div>')
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.detectChanges();
var offersComponentInstance = rootTC.componentViewChildren[0].componentInstance;
var componentDOMEl = rootTC.componentViewChildren[0].nativeElement;
var listLen = function () {
return offersComponentInstance.offers.length;
}
expect(offersComponentInstance.offers).toEqual(jasmine.any(HotelbookingServiceImpl.getOffers()));
expect(listLen()).toEqual(2);
expect(DOM.querySelectorAll(componentDOMEl, 'li').length).toEqual(listLen());
//offersComponentInstance.addName({value: 'Minko'});
HotelbookingServiceImpl.addOffer(new Offer('93475', 'Hotel Test', 98.98));
rootTC.detectChanges();
expect(listLen()).toEqual(3);
expect(DOM.querySelectorAll(componentDOMEl, 'li').length).toEqual(listLen());
expect(DOM.querySelectorAll(componentDOMEl, 'li')[4].textContent).toEqual('Hotel Test');
async.done();
});
}));
示例5: inject
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
tcb.createAsync(AppCmp).then((rootTC) => {
var router = rootTC.componentInstance.router;
PromiseWrapper.catchError(router.navigate('/cause-error'), (error) => {
expect(rootTC.nativeElement).toHaveText('outer { oh no }');
expect(error).toContainError('oops!');
async.done();
});
});
}));
示例6: inject
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var template = '<div>{{text}}<span ng-non-bindable>{{text}}</span></div>';
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('foo{{text}}');
async.done();
});
}));
示例7: inject
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideTemplate(TestComponent, '<div><home></home></div>')
.createAsync(TestComponent)
.then((rootTC) => {
let homeDOMEl = rootTC.debugElement.componentViewChildren[0].nativeElement;
expect(DOM.querySelectorAll(homeDOMEl, 'h1')[0].textContent).toEqual('Howdy!');
async.done();
});
}));