本文整理匯總了TypeScript中angular2/testing_internal.dispatchEvent函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript dispatchEvent函數的具體用法?TypeScript dispatchEvent怎麽用?TypeScript dispatchEvent使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了dispatchEvent函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: createComponent
createComponent(tcb).then((fixture: ComponentFixture) => {
usernameInput.value = 'barretodavid';
emailInput.value = 'barretollano@gmail.com';
dispatchEvent(usernameInput, 'input');
dispatchEvent(emailInput, 'input');
tick();
let data = element.querySelector('.submit-data');
expect(data).toHaveText('Value to submit: barretodavid, barretollano@gmail.com')
});
示例3: createComponent
createComponent(tcb).then((fixture) => {
input.value = 'ABC';
dispatchEvent(input, 'input');
tick();
fixture.detectChanges();
dispatchEvent(form, 'submit');
tick();
expect(fakeConsole._logs).toContain('you submitted value: ABC');
});
示例4: createComponent
return createComponent(tcb).then((fixture) => {
input.value = '';
dispatchEvent(input, 'input');
fixture.detectChanges();
let msgs = el.querySelectorAll('.ui.error.message');
expect(msgs[0]).toHaveText('SKU is invalid');
expect(msgs[1]).toHaveText('SKU is required');
});