From cf746ec73db50eae1ffaceb63f8839cf4dc3b537 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Tue, 27 Jun 2023 09:33:28 +0200 Subject: [PATCH] refactor(material/core): resolve flakes in ripple tests Fixes some flakes that have shown up in the ripple tests. It seems that sometimes the browser doesn't assign the `changedTouches` in tests which leads to flakiness. --- src/material/core/ripple/ripple-renderer.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/material/core/ripple/ripple-renderer.ts b/src/material/core/ripple/ripple-renderer.ts index 70471a4365c2..f3434e0ea4b5 100644 --- a/src/material/core/ripple/ripple-renderer.ts +++ b/src/material/core/ripple/ripple-renderer.ts @@ -382,10 +382,14 @@ export class RippleRenderer implements EventListenerObject { // Use `changedTouches` so we skip any touches where the user put // their finger down, but used another finger to tap the element again. - const touches = event.changedTouches; - - for (let i = 0; i < touches.length; i++) { - this.fadeInRipple(touches[i].clientX, touches[i].clientY, this._target.rippleConfig); + const touches = event.changedTouches as TouchList | undefined; + + // According to the typings the touches should always be defined, but in some cases + // the browser appears to not assign them in tests which leads to flakes. + if (touches) { + for (let i = 0; i < touches.length; i++) { + this.fadeInRipple(touches[i].clientX, touches[i].clientY, this._target.rippleConfig); + } } } }