How to use the @angular/cdk/testing/private.dispatchFakeEvent function in @angular/cdk

To help you get started, we’ve selected a few @angular/cdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github angular / components / src / cdk / a11y / focus-monitor / focus-monitor.spec.ts View on Github external
it('should detect focus via touch', fakeAsync(() => {
    // Simulate focus via touch.
    dispatchFakeEvent(buttonElement, 'touchstart');
    buttonElement.focus();
    fixture.detectChanges();
    tick(TOUCH_BUFFER_MS);

    expect(buttonElement.classList.length)
        .toBe(2, 'button should have exactly 2 focus classes');
    expect(buttonElement.classList.contains('cdk-focused'))
        .toBe(true, 'button should have cdk-focused class');
    expect(buttonElement.classList.contains('cdk-touch-focused'))
        .toBe(true, 'button should have cdk-touch-focused class');
    expect(changeHandler).toHaveBeenCalledWith('touch');
  }));
github angular / components / src / material / tabs / tab-header.spec.ts View on Github external
it('should clear the timeouts on click', fakeAsync(() => {
        dispatchFakeEvent(nextButton, 'mousedown');
        fixture.detectChanges();

        dispatchFakeEvent(nextButton, 'click');
        fixture.detectChanges();

        // No need to assert. If fakeAsync doesn't throw, it means that the timers were cleared.
      }));
github angular / components / src / material / progress-bar / progress-bar.spec.ts View on Github external
it('should trigger output event on primary value bar animation end', () => {
        fixture.detectChanges();
        spyOn(progressComponent.animationEnd, 'next');

        progressComponent.value = 40;
        expect(progressComponent.animationEnd.next).not.toHaveBeenCalled();

        // On animation end, output should be emitted.
        dispatchFakeEvent(primaryValueBar.nativeElement, 'transitionend');
        expect(progressComponent.animationEnd.next).toHaveBeenCalledWith({ value: 40 });
      });
    });
github angular / components / src / cdk / drag-drop / drag-drop-registry.spec.ts View on Github external
it('should prevent the default `selectstart` action when an item is being dragged', () => {
    registry.startDragging(testComponent.dragItems.first, createMouseEvent('mousedown'));
    expect(dispatchFakeEvent(document, 'selectstart').defaultPrevented).toBe(true);
  });
github angular / components / src / material / tabs / tab-header.spec.ts View on Github external
it('should show ripples for pagination buttons', () => {
        appComponent.addTabsForScrolling();
        fixture.detectChanges();

        expect(appComponent.tabHeader._showPaginationControls).toBe(true);

        const buttonAfter = fixture.debugElement.query(By.css('.mat-tab-header-pagination-after'))!;

        expect(fixture.nativeElement.querySelectorAll('.mat-ripple-element').length)
          .toBe(0, 'Expected no ripple to show up initially.');

        dispatchFakeEvent(buttonAfter.nativeElement, 'mousedown');
        dispatchFakeEvent(buttonAfter.nativeElement, 'mouseup');

        expect(fixture.nativeElement.querySelectorAll('.mat-ripple-element').length)
          .toBe(1, 'Expected one ripple to show up after mousedown');
      });
github angular / components / src / material / tabs / tab-header.spec.ts View on Github external
it('should re-align the ink bar when the window is resized', fakeAsync(() => {
      fixture = TestBed.createComponent(SimpleTabHeaderApp);
      fixture.detectChanges();

      const inkBar = fixture.componentInstance.tabHeader._inkBar;

      spyOn(inkBar, 'alignToElement');

      dispatchFakeEvent(window, 'resize');
      tick(150);
      fixture.detectChanges();

      expect(inkBar.alignToElement).toHaveBeenCalled();
      discardPeriodicTasks();
    }));
github angular / components / src / material / autocomplete / autocomplete.spec.ts View on Github external
it('should not throw when clicking outside', fakeAsync(() => {
      dispatchFakeEvent(fixture.debugElement.query(By.css('input'))!.nativeElement, 'focus');
      fixture.detectChanges();
      flush();

      expect(() => dispatchFakeEvent(document, 'click')).not.toThrow();
    }));
  });
github angular / components / src / material-experimental / mdc-chips / chip-grid.spec.ts View on Github external
it('should set aria-invalid if the form field is invalid', fakeAsync(() => {
      fixture.componentInstance.control = new FormControl(undefined, [Validators.required]);
      fixture.detectChanges();

      const input: HTMLInputElement = fixture.nativeElement.querySelector('input');

      expect(input.getAttribute('aria-invalid')).toBe('true');

      typeInElement(input, '123');
      fixture.detectChanges();
      dispatchKeyboardEvent(input, 'keydown', ENTER);
      fixture.detectChanges();
      tick();

      dispatchFakeEvent(input, 'blur');
      tick();

      fixture.detectChanges();
      expect(input.getAttribute('aria-invalid')).toBe('false');
    }));
  });
github angular / components / src / material-experimental / mdc-tabs / tab-header.spec.ts View on Github external
tick(300);

        expect(header.scrollDistance).toBe(0, 'Expected not to scroll after short amount of time.');

        tick(1000);

        expect(header.scrollDistance).toBeGreaterThan(0, 'Expected to scroll after some time.');

        let previousDistance = header.scrollDistance;

        tick(100);

        expect(header.scrollDistance)
            .toBeGreaterThan(previousDistance, 'Expected to scroll again after some more time.');

        dispatchFakeEvent(nextButton, endEventName);
      }
github angular / components / src / material / tabs / tab-header.spec.ts View on Github external
function assertNextButtonScrolling(startEventName: string, endEventName: string) {
        expect(header.scrollDistance).toBe(0, 'Expected to start off not scrolled.');

        dispatchFakeEvent(nextButton, startEventName);
        fixture.detectChanges();
        tick(300);

        expect(header.scrollDistance).toBe(0, 'Expected not to scroll after short amount of time.');

        tick(1000);

        expect(header.scrollDistance).toBeGreaterThan(0, 'Expected to scroll after some time.');

        let previousDistance = header.scrollDistance;

        tick(100);

        expect(header.scrollDistance)
            .toBeGreaterThan(previousDistance, 'Expected to scroll again after some more time.');