本文整理汇总了TypeScript中@angular/platform-browser/testing/browser_util.dispatchEvent函数的典型用法代码示例。如果您正苦于以下问题:TypeScript dispatchEvent函数的具体用法?TypeScript dispatchEvent怎么用?TypeScript dispatchEvent使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dispatchEvent函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: tick
tcb.overrideTemplate(MyComp8, t).createAsync(MyComp8).then((fixture) => {
fixture.detectChanges();
const form = fixture.debugElement.children[0].injector.get(NgForm).form;
fixture.detectChanges();
tick();
form.find('login').valueChanges.subscribe(
() => { expect(form.find('login').dirty).toBe(true); });
const loginEl = fixture.debugElement.query(By.css('input')).nativeElement;
loginEl.value = 'newValue';
dispatchEvent(loginEl, 'input');
});
示例2: dispatchEvent
tcb.overrideTemplate(MyComp8, t).createAsync(MyComp8).then((fixture) => {
var testComp: MyComp8 = fixture.debugElement.componentInstance;
testComp.list = [{'name': 'SF'}, {'name': 'NYC'}];
testComp.selectedCity = testComp.list[0];
fixture.detectChanges();
var select = fixture.debugElement.query(By.css('select'));
var ny = fixture.debugElement.queryAll(By.css('option'))[1];
select.nativeElement.value = '1: Object';
dispatchEvent(select.nativeElement, 'change');
testComp.list.push({'name': 'Buffalo'});
fixture.detectChanges();
expect(select.nativeElement.value).toEqual('1: Object');
expect(ny.nativeElement.selected).toBe(true);
async.done();
});
示例3: fakeAsync
fakeAsync(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
const t = `<div><input type="text" [(ngModel)]="name"></div>`;
let fixture = tcb.overrideTemplate(MyComp8, t).createFakeAsync(MyComp8);
tick();
fixture.debugElement.componentInstance.name = 'oldValue';
fixture.detectChanges();
var input = fixture.debugElement.query(By.css('input')).nativeElement;
tick();
expect(input.value).toEqual('oldValue');
input.value = 'updatedValue';
dispatchEvent(input, 'input');
tick();
expect(fixture.debugElement.componentInstance.name).toEqual('updatedValue');
})));