本文整理汇总了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();
}));