Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions docs/src/app/pages/component-sidenav/component-sidenav.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {provideZoneChangeDetection} from '@angular/core';
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {BreakpointObserver} from '@angular/cdk/layout';
import {MatSidenav} from '@angular/material/sidenav';
import {provideRouter, withComponentInputBinding} from '@angular/router';
import {RouterTestingHarness} from '@angular/router/testing';
import {of} from 'rxjs';
import {DocumentationItems} from '../../shared/documentation-items/documentation-items';
import {ComponentSidenav, componentSidenavRoutes} from './component-sidenav';

Expand All @@ -12,7 +14,16 @@ describe('ComponentSidenav', () => {

beforeEach(() => {
TestBed.configureTestingModule({
providers: [provideRouter([]), provideZoneChangeDetection()],
providers: [
provideRouter([]),
provideZoneChangeDetection(),
{
provide: BreakpointObserver,
useValue: {
observe: () => of({matches: true, breakpoints: {}}),
},
},
],
});

fixture = TestBed.createComponent(ComponentSidenav);
Expand All @@ -21,17 +32,9 @@ describe('ComponentSidenav', () => {
});

it('should close the sidenav on init', () => {
// Spy on window.mediaMatch and return stub
spyOn(window, 'matchMedia').and.returnValue({
matches: true,
} as any);

// TODO refactor this as none of these expectations are ever verified
waitForAsync(() => {
expect(component.sidenav() instanceof MatSidenav).toBeTruthy();
expect(component.isScreenSmall()).toBeTruthy();
expect(component.sidenav()!.opened).toBe(false);
});
expect(component.sidenav() instanceof MatSidenav).toBeTruthy();
expect(component.isScreenSmall()).toBeTruthy();
expect(component.sidenav()!.opened).toBe(false);
});

it('should show a link for each item in doc items categories', async () => {
Expand Down
6 changes: 3 additions & 3 deletions docs/src/app/shared/guide-items/guide-items.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {TestBed, waitForAsync} from '@angular/core/testing';
import {TestBed} from '@angular/core/testing';
import {GuideItems} from './guide-items';

describe('GuideItems', () => {
let guideItems: GuideItems;

beforeEach(waitForAsync(() => {
beforeEach(() => {
guideItems = TestBed.inject(GuideItems);
}));
});

it('should get a list of all guide items', () => {
expect(guideItems.getAllItems()).toBeDefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {CollectionViewer, DataSource} from '@angular/cdk/collections';
import {Platform} from '@angular/cdk/platform';
import {CdkTable, CdkTableModule} from '@angular/cdk/table';
import {Component, Type, ViewChild, ChangeDetectionStrategy} from '@angular/core';
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {BehaviorSubject, combineLatest} from 'rxjs';
import {map} from 'rxjs/operators';

Expand Down Expand Up @@ -50,7 +50,7 @@ describe('CdkTableScrollContainer', () => {
dataRows = getRows(tableElement);
});

it('sets scrollbar track margin for sticky headers', waitForAsync(async () => {
it('sets scrollbar track margin for sticky headers', async () => {
component.stickyHeaders = ['header-1', 'header-3'];
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
Expand All @@ -76,9 +76,9 @@ describe('CdkTableScrollContainer', () => {
expect(scrollerStyle.getPropertyValue('margin-right')).toBe('0px');
expect(scrollerStyle.getPropertyValue('margin-bottom')).toBe('0px');
expect(scrollerStyle.getPropertyValue('margin-left')).toBe('0px');
}));
});

it('sets scrollbar track margin for sticky footers', waitForAsync(async () => {
it('sets scrollbar track margin for sticky footers', async () => {
component.stickyFooters = ['footer-1', 'footer-3'];
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
Expand All @@ -104,9 +104,9 @@ describe('CdkTableScrollContainer', () => {
expect(scrollerStyle.getPropertyValue('margin-right')).toBe('0px');
expect(scrollerStyle.getPropertyValue('margin-bottom')).toBe('0px');
expect(scrollerStyle.getPropertyValue('margin-left')).toBe('0px');
}));
});

it('sets scrollbar track margin for sticky start columns', waitForAsync(async () => {
it('sets scrollbar track margin for sticky start columns', async () => {
component.stickyStartColumns = ['column-1', 'column-3'];
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
Expand Down Expand Up @@ -134,9 +134,9 @@ describe('CdkTableScrollContainer', () => {
expect(scrollerStyle.getPropertyValue('margin-right')).toBe('0px');
expect(scrollerStyle.getPropertyValue('margin-bottom')).toBe('0px');
expect(scrollerStyle.getPropertyValue('margin-left')).toBe('0px');
}));
});

it('sets scrollbar track margin for sticky end columns', waitForAsync(async () => {
it('sets scrollbar track margin for sticky end columns', async () => {
component.stickyEndColumns = ['column-4', 'column-6'];
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
Expand Down Expand Up @@ -164,9 +164,9 @@ describe('CdkTableScrollContainer', () => {
expect(scrollerStyle.getPropertyValue('margin-right')).toBe('0px');
expect(scrollerStyle.getPropertyValue('margin-bottom')).toBe('0px');
expect(scrollerStyle.getPropertyValue('margin-left')).toBe('0px');
}));
});

it('sets scrollbar track margin for a combination of sticky rows and columns', waitForAsync(async () => {
it('sets scrollbar track margin for a combination of sticky rows and columns', async () => {
component.stickyHeaders = ['header-1'];
component.stickyFooters = ['footer-3'];
component.stickyStartColumns = ['column-1'];
Expand Down Expand Up @@ -202,7 +202,7 @@ describe('CdkTableScrollContainer', () => {
expect(scrollerStyle.getPropertyValue('margin-right')).toBe('0px');
expect(scrollerStyle.getPropertyValue('margin-bottom')).toBe('0px');
expect(scrollerStyle.getPropertyValue('margin-left')).toBe('0px');
}));
});
});

interface TestData {
Expand Down
18 changes: 9 additions & 9 deletions src/cdk/a11y/focus-trap/focus-trap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
inject,
ChangeDetectionStrategy,
} from '@angular/core';
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {A11yModule, CdkTrapFocus, FocusTrap} from '../index';

Expand Down Expand Up @@ -215,7 +215,7 @@ describe('FocusTrap', () => {
});

describe('with autoCapture', () => {
it('should automatically capture and return focus on init / destroy', waitForAsync(() => {
it('should automatically capture and return focus on init / destroy', () => {
const fixture = TestBed.createComponent(FocusTrapWithAutoCapture);
fixture.detectChanges();

Expand All @@ -233,9 +233,9 @@ describe('FocusTrap', () => {
fixture.detectChanges();

expect(getActiveElement()).toBe(buttonOutsideTrappedRegion);
}));
});

it('should capture focus if auto capture is enabled later on', waitForAsync(() => {
it('should capture focus if auto capture is enabled later on', () => {
const fixture = TestBed.createComponent(FocusTrapWithAutoCapture);
fixture.componentInstance.autoCaptureEnabled = false;
fixture.componentInstance.showTrappedRegion = true;
Expand All @@ -256,9 +256,9 @@ describe('FocusTrap', () => {
fixture.detectChanges();

expect(getActiveElement()).toBe(buttonOutsideTrappedRegion);
}));
});

it('should automatically capture and return focus on init / destroy inside the shadow DOM', waitForAsync(() => {
it('should automatically capture and return focus on init / destroy inside the shadow DOM', () => {
if (!_supportsShadowDom()) {
return;
}
Expand All @@ -280,9 +280,9 @@ describe('FocusTrap', () => {
fixture.detectChanges();

expect(getActiveElement()).toBe(buttonOutsideTrappedRegion);
}));
});

it('should capture focus if auto capture is enabled later on inside the shadow DOM', waitForAsync(() => {
it('should capture focus if auto capture is enabled later on inside the shadow DOM', () => {
if (!_supportsShadowDom()) {
return;
}
Expand All @@ -307,7 +307,7 @@ describe('FocusTrap', () => {
fixture.detectChanges();

expect(getActiveElement()).toBe(buttonOutsideTrappedRegion);
}));
});
});

it('should put anchors inside the outlet when set at the root of a template portal', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/cdk/bidi/directionality.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import {waitForAsync, TestBed} from '@angular/core/testing';
import {TestBed} from '@angular/core/testing';
import {Component, ViewChild, signal, inject, ChangeDetectionStrategy} from '@angular/core';
import {By} from '@angular/platform-browser';
import {BidiModule, Directionality, Dir, Direction, DIR_DOCUMENT} from './index';

describe('Directionality', () => {
let fakeDocument: FakeDocument;

beforeEach(waitForAsync(() => {
beforeEach(() => {
fakeDocument = {body: {}, documentElement: {}};

TestBed.configureTestingModule({
providers: [{provide: DIR_DOCUMENT, useFactory: () => fakeDocument}],
});
}));
});

describe('Service', () => {
it('should read dir from the html element if not specified on the body', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/cdk/menu/menu-bar.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {
Component,
ElementRef,
Expand Down Expand Up @@ -45,14 +45,14 @@ describe('MenuBar', () => {
let fixture: ComponentFixture<MenuBarRadioGroup>;
let menuItems: CdkMenuItemRadio[];

beforeEach(waitForAsync(() => {
beforeEach(() => {
fixture = TestBed.createComponent(MenuBarRadioGroup);
fixture.detectChanges();

menuItems = fixture.debugElement
.queryAll(By.directive(CdkMenuItemRadio))
.map(element => element.injector.get(CdkMenuItemRadio));
}));
});

it('should toggle menuitemradio items', () => {
expect(menuItems[0].checked).toBeTrue();
Expand Down
10 changes: 5 additions & 5 deletions src/cdk/menu/menu-group.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Component, ViewChild, ChangeDetectionStrategy} from '@angular/core';
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {CdkMenuModule} from './menu-module';
import {CdkMenuItemCheckbox} from './menu-item-checkbox';
Expand All @@ -11,7 +11,7 @@ describe('MenuGroup', () => {
let fixture: ComponentFixture<CheckboxMenu>;
let menuItems: CdkMenuItemCheckbox[];

beforeEach(waitForAsync(() => {
beforeEach(() => {
fixture = TestBed.createComponent(CheckboxMenu);
fixture.detectChanges();

Expand All @@ -21,7 +21,7 @@ describe('MenuGroup', () => {
menuItems = fixture.debugElement
.queryAll(By.directive(CdkMenuItemCheckbox))
.map(e => e.injector.get(CdkMenuItemCheckbox));
}));
});

it('should not change state of sibling checked menuitemcheckbox', () => {
menuItems[1].trigger();
Expand All @@ -34,7 +34,7 @@ describe('MenuGroup', () => {
let fixture: ComponentFixture<MenuWithMultipleRadioGroups>;
let menuItems: CdkMenuItemRadio[];

beforeEach(waitForAsync(() => {
beforeEach(() => {
fixture = TestBed.createComponent(MenuWithMultipleRadioGroups);
fixture.detectChanges();

Expand All @@ -44,7 +44,7 @@ describe('MenuGroup', () => {
menuItems = fixture.debugElement
.queryAll(By.directive(CdkMenuItemRadio))
.map(e => e.injector.get(CdkMenuItemRadio));
}));
});

it('should change state of sibling menuitemradio in same group', () => {
menuItems[1].trigger({keepOpen: true});
Expand Down
6 changes: 3 additions & 3 deletions src/cdk/menu/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ViewChildren,
ChangeDetectionStrategy,
} from '@angular/core';
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {
createMouseEvent,
Expand All @@ -25,7 +25,7 @@ describe('Menu', () => {
let fixture: ComponentFixture<MenuCheckboxGroup>;
let menuItems: CdkMenuItemCheckbox[];

beforeEach(waitForAsync(() => {
beforeEach(() => {
fixture = TestBed.createComponent(MenuCheckboxGroup);
fixture.detectChanges();

Expand All @@ -35,7 +35,7 @@ describe('Menu', () => {
menuItems = fixture.debugElement
.queryAll(By.directive(CdkMenuItemCheckbox))
.map(element => element.injector.get(CdkMenuItemCheckbox));
}));
});

it('should toggle menuitemcheckbox', () => {
expect(menuItems[0].checked).toBeTrue();
Expand Down
14 changes: 7 additions & 7 deletions src/cdk/observers/private/shared-resize-observer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {Component, ElementRef, inject, ViewChild, ChangeDetectionStrategy} from '@angular/core';
import {SharedResizeObserver} from './shared-resize-observer';

Expand Down Expand Up @@ -93,7 +93,7 @@ describe('SharedResizeObserver', () => {
expect(observable1).not.toBe(observable3);
});

it('should receive an initial size on subscription', waitForAsync(async () => {
it('should receive an initial size on subscription', async () => {
const observable = resizeObserver.observe(el1);
const resizeSpy1 = jasmine.createSpy('resize handler 1');
observable.subscribe(resizeSpy1);
Expand All @@ -103,19 +103,19 @@ describe('SharedResizeObserver', () => {
observable.subscribe(resizeSpy2);
fixture.detectChanges();
expect(resizeSpy2).toHaveBeenCalled();
}));
});

it('should receive events on resize', waitForAsync(async () => {
it('should receive events on resize', async () => {
const resizeSpy = jasmine.createSpy('resize handler');
resizeObserver.observe(el1).subscribe(resizeSpy);
fixture.detectChanges();
resizeSpy.calls.reset();
currentObservers.get('content-box')?.triggerCallback(el1);
fixture.detectChanges();
expect(resizeSpy).toHaveBeenCalled();
}));
});

it('should not receive events for other elements', waitForAsync(async () => {
it('should not receive events for other elements', async () => {
const resizeSpy1 = jasmine.createSpy('resize handler 1');
const resizeSpy2 = jasmine.createSpy('resize handler 2');
resizeObserver.observe(el1).subscribe(resizeSpy1);
Expand All @@ -127,7 +127,7 @@ describe('SharedResizeObserver', () => {
fixture.detectChanges();
expect(resizeSpy1).toHaveBeenCalled();
expect(resizeSpy2).not.toHaveBeenCalled();
}));
});
});

@Component({
Expand Down
6 changes: 3 additions & 3 deletions src/cdk/overlay/fullscreen-overlay-container.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {waitForAsync, TestBed} from '@angular/core/testing';
import {TestBed} from '@angular/core/testing';
import {
Component,
ViewChild,
Expand All @@ -16,7 +16,7 @@ describe('FullscreenOverlayContainer', () => {
let fullscreenListeners: Set<Function>;
let fakeDocument: any;

beforeEach(waitForAsync(() => {
beforeEach(() => {
fullscreenListeners = new Set();

TestBed.configureTestingModule({
Expand Down Expand Up @@ -68,7 +68,7 @@ describe('FullscreenOverlayContainer', () => {

injector = TestBed.inject(Injector);
fakeDocument = TestBed.inject(DOCUMENT);
}));
});

it('should open an overlay inside a fullscreen element and move it to the body', () => {
const fixture = TestBed.createComponent(TestComponentWithTemplatePortals);
Expand Down
Loading
Loading