Skip to content

Commit 613f84a

Browse files
committed
test(material-experimental/mdc-slider): try to reduce test flakes
We've been seeing more test flakes from the MDC slider recently. These changes try to address them by disabling animations and adding an extra change detection after flushing `requestAnimationFrame`.
1 parent 49de56c commit 613f84a

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/material-experimental/mdc-slider/slider.spec.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,19 @@ import {Component, DebugElement, Type, ViewChild} from '@angular/core';
2424
import {ComponentFixture, fakeAsync, flush, TestBed, tick, inject} from '@angular/core/testing';
2525
import {FormControl, FormsModule, ReactiveFormsModule} from '@angular/forms';
2626
import {By} from '@angular/platform-browser';
27+
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
2728
import {MatSlider, MatSliderModule} from './index';
2829

2930
describe('MDC-based MatSlider', () => {
3031
function createComponent<T>(component: Type<T>): ComponentFixture<T> {
3132
TestBed.configureTestingModule({
32-
imports: [MatSliderModule, ReactiveFormsModule, FormsModule, BidiModule],
33+
imports: [
34+
MatSliderModule,
35+
ReactiveFormsModule,
36+
FormsModule,
37+
BidiModule,
38+
NoopAnimationsModule,
39+
],
3340
declarations: [component],
3441
}).compileComponents();
3542

@@ -215,6 +222,7 @@ describe('MDC-based MatSlider', () => {
215222
// Flush the "requestAnimationFrame" timer that performs the initial
216223
// rendering of the MDC slider.
217224
flushRequestAnimationFrame();
225+
fixture.detectChanges();
218226
}));
219227

220228
it('should set the default values from the attributes', () => {
@@ -247,6 +255,7 @@ describe('MDC-based MatSlider', () => {
247255
dispatchMousedownEventSequence(sliderNativeElement, 0.68);
248256
fixture.detectChanges();
249257
flushRequestAnimationFrame();
258+
fixture.detectChanges();
250259

251260
// The closest snap is halfway on the slider.
252261
expect(thumbContainerEl.style.transform).toContain('translateX(50px)');
@@ -256,6 +265,7 @@ describe('MDC-based MatSlider', () => {
256265
dispatchSlideEventSequence(sliderNativeElement, 0, 0.74);
257266
fixture.detectChanges();
258267
flushRequestAnimationFrame();
268+
fixture.detectChanges();
259269

260270
// The closest snap is at the halfway point on the slider.
261271
expect(thumbContainerEl.style.transform).toContain('translateX(50px)');
@@ -318,6 +328,7 @@ describe('MDC-based MatSlider', () => {
318328
// Flush the "requestAnimationFrame" timer that performs the initial
319329
// rendering of the MDC slider.
320330
flushRequestAnimationFrame();
331+
fixture.detectChanges();
321332
}));
322333

323334
it('should set the correct step value on mousedown', () => {
@@ -342,6 +353,7 @@ describe('MDC-based MatSlider', () => {
342353
dispatchMousedownEventSequence(sliderNativeElement, 0.66);
343354
fixture.detectChanges();
344355
flushRequestAnimationFrame();
356+
fixture.detectChanges();
345357

346358
// The closest step is at 75% of the slider.
347359
expect(thumbContainerEl.style.transform).toContain('translateX(75px)');
@@ -358,6 +370,7 @@ describe('MDC-based MatSlider', () => {
358370
dispatchSlideEventSequence(sliderNativeElement, 0, 0.88);
359371
fixture.detectChanges();
360372
flushRequestAnimationFrame();
373+
fixture.detectChanges();
361374

362375
// The closest snap is at the end of the slider.
363376
expect(thumbContainerEl.style.transform).toContain('translateX(100px)');
@@ -539,6 +552,7 @@ describe('MDC-based MatSlider', () => {
539552
// Flush the "requestAnimationFrame" timer that performs the initial
540553
// rendering of the MDC slider.
541554
flushRequestAnimationFrame();
555+
fixture.detectChanges();
542556
}));
543557

544558
it('should initialize based on bound value', () => {
@@ -550,6 +564,7 @@ describe('MDC-based MatSlider', () => {
550564
testComponent.val = 75;
551565
fixture.detectChanges();
552566
flushRequestAnimationFrame();
567+
fixture.detectChanges();
553568

554569
expect(sliderInstance.value).toBe(75);
555570
expect(thumbContainerEl.style.transform).toContain('translateX(75px)');
@@ -576,6 +591,7 @@ describe('MDC-based MatSlider', () => {
576591
// Flush the "requestAnimationFrame" timer that performs the initial
577592
// rendering of the MDC slider.
578593
flushRequestAnimationFrame();
594+
fixture.detectChanges();
579595
}));
580596

581597
it('should set the value smaller than the min value', () => {
@@ -609,6 +625,7 @@ describe('MDC-based MatSlider', () => {
609625
// Flush the "requestAnimationFrame" timer that performs the initial
610626
// rendering of the MDC slider.
611627
flushRequestAnimationFrame();
628+
fixture.detectChanges();
612629
}));
613630

614631
it('should set the value greater than the max value', () => {
@@ -758,6 +775,7 @@ describe('MDC-based MatSlider', () => {
758775
<HTMLElement>sliderNativeElement.querySelector('.mdc-slider__track-marker-container');
759776

760777
flushRequestAnimationFrame();
778+
fixture.detectChanges();
761779
}));
762780

763781
it('should set the correct tick separation', () => {
@@ -955,6 +973,7 @@ describe('MDC-based MatSlider', () => {
955973
testComponent.dir = 'rtl';
956974
fixture.detectChanges();
957975
flushRequestAnimationFrame();
976+
fixture.detectChanges();
958977

959978
dispatchMousedownEventSequence(sliderNativeElement, 0.3);
960979
fixture.detectChanges();
@@ -966,6 +985,7 @@ describe('MDC-based MatSlider', () => {
966985
testComponent.dir = 'rtl';
967986
fixture.detectChanges();
968987
flushRequestAnimationFrame();
988+
fixture.detectChanges();
969989

970990
const thumbContainerEl = <HTMLElement>sliderNativeElement
971991
.querySelector('.mdc-slider__thumb-container');
@@ -975,6 +995,7 @@ describe('MDC-based MatSlider', () => {
975995
testComponent.dir = 'ltr';
976996
fixture.detectChanges();
977997
flushRequestAnimationFrame();
998+
fixture.detectChanges();
978999

9791000
expect(thumbContainerEl.style.transform).toContain('translateX(0px)');
9801001
}));

0 commit comments

Comments
 (0)