Skip to content

Commit 05927b3

Browse files
jelbournandrewseguin
authored andcommitted
test(scrolling): correctly treat TestBed.compileComponents as async (#14922)
Tests for cdk/scrolling previously assumed that Test.compileComponents completes synchronously, immediately instantiating components after calling the compile. This is not true, and the tests only work by coicidence. With ivy, this is not as lenient and starts failing.
1 parent dc435f7 commit 05927b3

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/cdk-experimental/scrolling/virtual-scroll-viewport.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {CdkVirtualScrollViewport, ScrollingModule} from '@angular/cdk/scrolling';
22
import {Component, Input, ViewChild, ViewEncapsulation} from '@angular/core';
3-
import {ComponentFixture, fakeAsync, flush, TestBed} from '@angular/core/testing';
3+
import {async, ComponentFixture, fakeAsync, flush, TestBed} from '@angular/core/testing';
44
import {ScrollingModule as ExperimentalScrollingModule} from './scrolling-module';
55

66

@@ -10,12 +10,14 @@ describe('CdkVirtualScrollViewport', () => {
1010
let testComponent: AutoSizeVirtualScroll;
1111
let viewport: CdkVirtualScrollViewport;
1212

13-
beforeEach(() => {
13+
beforeEach(async(() => {
1414
TestBed.configureTestingModule({
1515
imports: [ScrollingModule, ExperimentalScrollingModule],
1616
declarations: [AutoSizeVirtualScroll],
1717
}).compileComponents();
18+
}));
1819

20+
beforeEach(() => {
1921
fixture = TestBed.createComponent(AutoSizeVirtualScroll);
2022
testComponent = fixture.componentInstance;
2123
viewport = testComponent.viewport;

src/cdk/scrolling/scrollable.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ describe('CdkScrollable', () => {
2727
imports: [ScrollingModule],
2828
declarations: [ScrollableViewport],
2929
}).compileComponents();
30+
}));
3031

32+
beforeEach(() => {
3133
fixture = TestBed.createComponent(ScrollableViewport);
3234
testComponent = fixture.componentInstance;
33-
}));
35+
});
3436

3537
describe('in LTR context', () => {
3638
beforeEach(() => {

src/cdk/scrolling/virtual-scroll-viewport.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
ViewContainerRef,
1616
ViewEncapsulation
1717
} from '@angular/core';
18-
import {ComponentFixture, fakeAsync, flush, inject, TestBed} from '@angular/core/testing';
18+
import {async, ComponentFixture, fakeAsync, flush, inject, TestBed} from '@angular/core/testing';
1919
import {animationFrameScheduler, Subject} from 'rxjs';
2020

2121

@@ -25,12 +25,14 @@ describe('CdkVirtualScrollViewport', () => {
2525
let testComponent: FixedSizeVirtualScroll;
2626
let viewport: CdkVirtualScrollViewport;
2727

28-
beforeEach(() => {
28+
beforeEach(async(() => {
2929
TestBed.configureTestingModule({
3030
imports: [ScrollingModule],
3131
declarations: [FixedSizeVirtualScroll],
3232
}).compileComponents();
33+
}));
3334

35+
beforeEach(() => {
3436
fixture = TestBed.createComponent(FixedSizeVirtualScroll);
3537
testComponent = fixture.componentInstance;
3638
viewport = testComponent.viewport;

0 commit comments

Comments
 (0)