diff --git a/components/TextFields/tests/snapshot/supplemental/MDCTextFieldSnapshotTestCase.m b/components/TextFields/tests/snapshot/supplemental/MDCTextFieldSnapshotTestCase.m index 7107c75801b..607bf89013b 100644 --- a/components/TextFields/tests/snapshot/supplemental/MDCTextFieldSnapshotTestCase.m +++ b/components/TextFields/tests/snapshot/supplemental/MDCTextFieldSnapshotTestCase.m @@ -25,7 +25,19 @@ - (void)setUp { self.textField = [[SnapshotFakeMDCTextField alloc] init]; } +- (void)removeAllSubviewsFromSuperviews:(UIView *)view { + NSArray *subviews = [view.subviews copy]; + for (UIView *subview in subviews) { + [self removeAllSubviewsFromSuperviews:subview]; + } + [view removeFromSuperview]; +} + - (void)tearDown { + // This is required to invalidate any pending UITextField caret blink timers. + // Calling `removeFromSuperview` on `self.textField` is insufficient. + // See https://github.com/material-components/material-components-ios/issues/6181 + [self removeAllSubviewsFromSuperviews:self.textField]; self.textField = nil; [super tearDown];