当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript testing.dispatchEvent函数代码示例

本文整理汇总了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);
    });
开发者ID:GerbenRampaart,项目名称:ngbook2,代码行数:8,代码来源:demo_form_with_validations_explicit.spec.ts

示例2: dispatchEvent

 Object.keys(inputDict).forEach(key => {
     input = fixture.debugElement.query(By.css(`input[name="${key}"]`)).nativeElement;
     input.value = inputDict[key];
     dispatchEvent(input, 'input');
 });
开发者ID:6Kbrouette,项目名称:wt-training-angular2,代码行数:5,代码来源:user-list.component.spec.ts

示例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();

    }));
开发者ID:6Kbrouette,项目名称:wt-training-angular2,代码行数:93,代码来源:user-list.component.spec.ts


注:本文中的@angular/platform-browser/testing.dispatchEvent函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。