本文整理汇总了TypeScript中@angular/platform-browser/src/dom/debug/by.By类的典型用法代码示例。如果您正苦于以下问题:TypeScript By类的具体用法?TypeScript By怎么用?TypeScript By使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了By类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('can follow the user', () => {
const cmp:FollowBtnComponent = cmpDebugElement.componentInstance;
const testCmp:TestComponent = testCmpDebugElement.componentInstance;
spyOn(testCmp, 'doSomething');
const followBtn = cmpDebugElement.query(By.css('button'));
followBtn.nativeElement.click();
expect(cmp.canShowFollowBtn).toBeFalsy();
expect(cmp.canShowUnfollowBtn).toBeTruthy();
expect(followBtnService.follow).toHaveBeenCalledWith('1');
expect(testCmp.doSomething).toHaveBeenCalled();
});
示例2: tick
tcb.overrideTemplate(MyComp8, t).createAsync(MyComp8).then((fixture) => {
var testComp = fixture.debugElement.componentInstance;
testComp.list = [{'name': 'SF'}, {'name': 'NYC'}, {'name': 'Buffalo'}];
testComp.selectedCity = testComp.list[1];
fixture.detectChanges();
var select = fixture.debugElement.query(By.css('select'));
var nycOption = fixture.debugElement.queryAll(By.css('option'))[1];
tick();
expect(select.nativeElement.value).toEqual('1: Object');
expect(nycOption.nativeElement.selected).toBe(true);
select.nativeElement.value = '2: Object';
dispatchEvent(select.nativeElement, 'change');
fixture.detectChanges();
tick();
expect(testComp.selectedCity['name']).toEqual('Buffalo');
});
示例3: it
it('can list users', () => {
const page:UserListComponent = cmpDebugElement.componentInstance;
expect(page.users.length).toEqual(2);
expect(page.totalPages).toEqual(1);
const el = cmpDebugElement.nativeElement;
expect(getDOM().querySelectorAll(el, 'li>a')[0].innerText).toEqual('test1');
expect(getDOM().querySelectorAll(el, 'li>a')[1].innerText).toEqual('test2');
const gravatarDebugElement = cmpDebugElement.query(By.directive(GravatarComponent));
expect(gravatarDebugElement).toBeTruthy();
expect(gravatarDebugElement.componentInstance.email).toEqual('test1@test.com');
expect(gravatarDebugElement.componentInstance.alt).toEqual('test1');
const userShowLink = cmpDebugElement.query(By.css('li>a')).nativeElement;
expect(userShowLink.getAttribute('href')).toEqual('/users/1');
const pager:PagerComponent = pagerDebugElement.componentInstance;
expect(pager.totalPages).toEqual(1);
});
示例4: expect
tcb.overrideTemplate(MyComp8, t).createAsync(MyComp8).then((fixture) => {
fixture.debugElement.componentInstance.name = '';
fixture.detectChanges();
const form = fixture.debugElement.query(By.css('form')).nativeElement;
const modelGroup =
fixture.debugElement.query(By.directive(NgModelGroup)).nativeElement;
const input = fixture.debugElement.query(By.css('input')).nativeElement;
// ngModelGroup creates its control asynchronously
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(sortedClassList(modelGroup)).toEqual([
'ng-invalid', 'ng-pristine', 'ng-untouched'
]);
expect(sortedClassList(form)).toEqual([
'ng-invalid', 'ng-pristine', 'ng-untouched'
]);
dispatchEvent(input, 'blur');
fixture.detectChanges();
expect(sortedClassList(modelGroup)).toEqual([
'ng-invalid', 'ng-pristine', 'ng-touched'
]);
expect(sortedClassList(form)).toEqual(['ng-invalid', 'ng-pristine', 'ng-touched']);
input.value = 'updatedValue';
dispatchEvent(input, 'input');
fixture.detectChanges();
expect(sortedClassList(modelGroup)).toEqual([
'ng-dirty', 'ng-touched', 'ng-valid'
]);
expect(sortedClassList(form)).toEqual(['ng-dirty', 'ng-touched', 'ng-valid']);
});
async.done();
});
示例5: fakeAsync
fakeAsync(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
const t = `<div><form (ngSubmit)="name='updated'"></form></div>`;
let fixture = tcb.overrideTemplate(MyComp8, t).createFakeAsync(MyComp8);
tick();
fixture.debugElement.componentInstance.name = 'old';
var form = fixture.debugElement.query(By.css('form'));
dispatchEvent(form.nativeElement, 'submit');
tick();
expect(fixture.debugElement.componentInstance.name).toEqual('updated');
})));
示例6: expect
() => {
const fixture = TestBed.createComponent(SomeApp);
const cmp = fixture.debugElement.query(By.css('cmp-native')).nativeElement;
const native = cmp.shadowRoot.querySelector('.native');
expect(window.getComputedStyle(native).color).toEqual('rgb(255, 0, 0)');
const emulated = cmp.shadowRoot.querySelector('.emulated');
expect(window.getComputedStyle(emulated).color).toEqual('rgb(0, 0, 255)');
const none = cmp.shadowRoot.querySelector('.none');
expect(window.getComputedStyle(none).color).toEqual('rgb(0, 255, 0)');
});
示例7: it
it('should support dotted selectors', async(() => {
@Directive({selector: '[dot.name]'})
class MyDir {
@Input('dot.name') value: string;
}
TestBed.configureTestingModule({
declarations: [
MyDir,
TestComponent,
],
});
const template = `<div [dot.name]="'foo'"></div>`;
fixture = createTestComponent(template);
fixture.detectChanges();
const myDir = fixture.debugElement.query(By.directive(MyDir)).injector.get(MyDir);
expect(myDir.value).toEqual('foo');
}));