|
2 | 2 | async, ComponentFixture, TestBed, tick, fakeAsync, |
3 | 3 | flushMicrotasks |
4 | 4 | } from '@angular/core/testing'; |
5 | | -import {Component, DebugElement} from '@angular/core'; |
| 5 | +import {Component, DebugElement, AnimationTransitionEvent} from '@angular/core'; |
6 | 6 | import {By} from '@angular/platform-browser'; |
7 | 7 | import {TooltipPosition, MdTooltip, TOOLTIP_HIDE_DELAY, MdTooltipModule} from './tooltip'; |
8 | 8 | import {OverlayContainer} from '../core'; |
@@ -123,14 +123,45 @@ describe('MdTooltip', () => { |
123 | 123 | expect(overlayContainerElement.childNodes.length).toBe(0); |
124 | 124 | expect(overlayContainerElement.textContent).toBe(''); |
125 | 125 | }); |
| 126 | + |
| 127 | + it('should not try to dispose the tooltip when destroyed and done hiding', fakeAsync(() => { |
| 128 | + tooltipDirective.show(); |
| 129 | + fixture.detectChanges(); |
| 130 | + tick(150); |
| 131 | + |
| 132 | + tooltipDirective.hide(); |
| 133 | + tick(TOOLTIP_HIDE_DELAY); // Change the tooltip state to hidden and trigger animation start |
| 134 | + |
| 135 | + // Store the tooltip instance, which will be set to null after the button is hidden. |
| 136 | + const tooltipInstance = tooltipDirective._tooltipInstance; |
| 137 | + fixture.componentInstance.showButton = false; |
| 138 | + fixture.detectChanges(); |
| 139 | + |
| 140 | + // At this point the animation should be able to complete itself and trigger the |
| 141 | + // _afterVisibilityAnimation function, but for unknown reasons in the test infrastructure, |
| 142 | + // this does not occur. Manually call this and verify that doing so does not |
| 143 | + // throw an error. |
| 144 | + tooltipInstance._afterVisibilityAnimation(new AnimationTransitionEvent({ |
| 145 | + fromState: 'visible', |
| 146 | + toState: 'hidden', |
| 147 | + totalTime: 150, |
| 148 | + phaseName: '', |
| 149 | + })); |
| 150 | + })); |
126 | 151 | }); |
127 | 152 | }); |
128 | 153 |
|
129 | 154 | @Component({ |
130 | 155 | selector: 'app', |
131 | | - template: `<button [md-tooltip]="message" [tooltip-position]="position">Button</button>` |
| 156 | + template: ` |
| 157 | + <button *ngIf="showButton" |
| 158 | + [md-tooltip]="message" |
| 159 | + [tooltip-position]="position"> |
| 160 | + Button |
| 161 | + </button>` |
132 | 162 | }) |
133 | 163 | class BasicTooltipDemo { |
134 | 164 | position: TooltipPosition = 'below'; |
135 | 165 | message: string = initialTooltipMessage; |
| 166 | + showButton: boolean = true; |
136 | 167 | } |
0 commit comments