當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。