本文整理汇总了TypeScript中angular2/platform/browser.By类的典型用法代码示例。如果您正苦于以下问题:TypeScript By类的具体用法?TypeScript By怎么用?TypeScript By使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了By类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: dispatchEvent
tcb.createAsync(DemoFormWithEvents).then((fixture) => {
let el = fixture.debugElement.nativeElement;
let input = fixture.debugElement.query(By.css("input")).nativeElement;
let form = fixture.debugElement.query(By.css("form")).nativeElement;
fixture.detectChanges();
input.value = '';
dispatchEvent(input, 'input');
fixture.detectChanges();
tick();
// no value on sku field, all error messages are displayed
let msgs = el.querySelectorAll('.ui.error.message');
expect(msgs[0]).toHaveText('SKU is invalid');
expect(msgs[1]).toHaveText('SKU is required');
// displays no errors when sku has a value
input.value = 'XYZ';
dispatchEvent(input, 'input');
fixture.detectChanges();
tick()
msgs = el.querySelectorAll('.ui.error.message');
expect(msgs.length).toEqual(0);
fixture.detectChanges();
dispatchEvent(form, 'submit');
tick();
// checks for the form submitted message
expect(fakeConsole._logs).toContain('you submitted value: XYZ');
});
示例2:
.then((fixture: ComponentFixture) => {
element = fixture.debugElement.nativeElement;
form = fixture.debugElement.query(By.css('form')).nativeElement;
usernameInput = fixture.debugElement.query(By.css('#username')).nativeElement;
emailInput = fixture.debugElement.query(By.css('#email')).nativeElement;
fixture.detectChanges();
return fixture;
});
示例3:
return tcb.createAsync(DemoFormWithEvents).then((fixture) => {
el = fixture.debugElement.nativeElement;
input = fixture.debugElement.query(By.css("input")).nativeElement;
form = fixture.debugElement.query(By.css("form")).nativeElement;
fixture.detectChanges();
return fixture;
});
示例4:
.then((fixture: ComponentFixture) => {
let element = fixture.debugElement.nativeElement;
let form = fixture.debugElement.query(By.css('form')).nativeElement;
let usernameInput = fixture.debugElement.query(By.css('#username')).nativeElement;
let emailInput = fixture.debugElement.query(By.css('#email')).nativeElement;
fixture.detectChanges();
return {element, form, usernameInput, emailInput, fixture};
});
示例5: expect
.then((fixture) => {
let button = fixture.debugElement.query(By.css('md-radio-button'));
let input = button.query(By.css('input'));
fixture.detectChanges();
expect(button.componentInstance.checked).toBe(false);
let event = createEvent('change');
input.nativeElement.dispatchEvent(event);
expect(button.componentInstance.checked).toBe(true);
}).then(done);
示例6:
return prep.then((fixture: ComponentFixture) => {
fixture.detectChanges();
let debug = fixture.debugElement.query(By.css('md-sidenav'));
let cdebug = fixture.debugElement.query(By.css('md-sidenav-container'));
return {
fixture: fixture,
component: debug.componentInstance,
debug: debug,
cdebug: cdebug,
container: cdebug ? cdebug.componentInstance : null
};
}).catch(console.error.bind(console));
示例7: expect
.then((fixture) => {
fixture.detectChanges();
let progressElement = fixture.debugElement.query(By.css('md-progress-bar'));
let progressComponent = progressElement.componentInstance;
expect(progressComponent.primaryTransform()).toBe('scaleX(0)');
expect(progressComponent.bufferTransform()).toBe(undefined);
progressComponent.value = 40;
expect(progressComponent.primaryTransform()).toBe('scaleX(0.4)');
expect(progressComponent.bufferTransform()).toBe(undefined);
progressComponent.value = 35;
progressComponent.bufferValue = 55;
expect(progressComponent.primaryTransform()).toBe('scaleX(0.35)');
expect(progressComponent.bufferTransform()).toBe(undefined);
progressComponent.mode = 'buffer';
expect(progressComponent.primaryTransform()).toBe('scaleX(0.35)');
expect(progressComponent.bufferTransform()).toBe('scaleX(0.55)');
progressComponent.value = 60;
progressComponent.bufferValue = 60;
expect(progressComponent.primaryTransform()).toBe('scaleX(0.6)');
expect(progressComponent.bufferTransform()).toBe('scaleX(0.6)');
done();
});