本文整理匯總了TypeScript中@angular/platform-browser/testing.dispatchEvent函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript dispatchEvent函數的具體用法?TypeScript dispatchEvent怎麽用?TypeScript dispatchEvent使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了dispatchEvent函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: createComponent
return createComponent(tcb).then((fixture) => {
input.value = 'ABC';
dispatchEvent(input, 'input');
fixture.detectChanges();
let msgs = el.querySelectorAll('.ui.error.message');
expect(msgs.length).toEqual(0);
});
示例2: dispatchEvent
Object.keys(inputDict).forEach(key => {
input = fixture.debugElement.query(By.css(`input[name="${key}"]`)).nativeElement;
input.value = inputDict[key];
dispatchEvent(input, 'input');
});
示例3: it
it('should add user', fakeAsync(() => {
let elementList = null;
let fixture: ComponentFixture<UserListComponent> = null;
let input = null;
let inputDict = {
firstName: 'Guido',
lastName: 'VAN ROSSUM',
email: 'guido@python.org'
};
spyConnection = jasmine.createSpy('connection');
spyConnection.and.returnValue({
body: {
objects: [
{
id: 'USER_ID_1',
firstName: 'fOO',
lastName: 'bar',
email: 'foo.bar@wishtack.com'
},
{
id: 'USER_ID_2',
firstName: 'john',
lastName: 'woo',
email: 'john.woo@wishtack.com'
}
]
},
status: 200
});
fixture = this.testComponentBuilder
.createFakeAsync(UserListComponent);
fixture.detectChanges();
spyConnection = jasmine.createSpy('connection');
spyConnection.and.returnValue({
status: 200,
body: {
id: 'USER_ID_3',
firstName: 'Guido',
lastName: 'VAN ROSSUM',
email: 'guido@python.org'
}
});
/* Add user. */
Object.keys(inputDict).forEach(key => {
input = fixture.debugElement.query(By.css(`input[name="${key}"]`)).nativeElement;
input.value = inputDict[key];
dispatchEvent(input, 'input');
});
/* Update form status after validation. */
fixture.detectChanges();
dispatchEvent(fixture.debugElement.query(By.css('wt-user-edit form button[type="submit"]')).nativeElement, 'click');
dispatchEvent(fixture.debugElement.query(By.css('wt-user-edit form')).nativeElement, 'submit');
tick();
expect(spyConnection.calls.count()).toEqual(1);
expect(spyConnection).toHaveBeenCalledWith({
body: JSON.stringify({
id: null,
firstName: 'Guido',
lastName: 'VAN ROSSUM',
email: 'guido@python.org'
}),
method: RequestMethod.Post,
url: '/api/v1/users/'
});
/* Trigger change detection. */
fixture.detectChanges();
/* Check user list. */
elementList = fixture.debugElement.queryAll(By.css('wt-user-display'));
expect(elementList.length).toEqual(3);
expect(elementList[0].nativeElement.innerText.trim()).toEqual('Foo BAR foo.bar@wishtack.com');
expect(elementList[1].nativeElement.innerText.trim()).toEqual('John WOO john.woo@wishtack.com');
expect(elementList[2].nativeElement.innerText.trim()).toEqual('Guido VAN ROSSUM guido@python.org');
/* @hack: Avoiding 'periodic timer(s) still in the queue' error due to rxjs timeout operator. */
tick(5000);
fixture.destroy();
}));