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