|
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,44 @@ 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 | + })); |
| 149 | + })); |
126 | 150 | });
|
127 | 151 | });
|
128 | 152 |
|
129 | 153 | @Component({
|
130 | 154 | selector: 'app',
|
131 |
| - template: `<button [md-tooltip]="message" [tooltip-position]="position">Button</button>` |
| 155 | + template: ` |
| 156 | + <button *ngIf="showButton" |
| 157 | + [md-tooltip]="message" |
| 158 | + [tooltip-position]="position"> |
| 159 | + Button |
| 160 | + </button>` |
132 | 161 | })
|
133 | 162 | class BasicTooltipDemo {
|
134 | 163 | position: TooltipPosition = 'below';
|
135 | 164 | message: string = initialTooltipMessage;
|
| 165 | + showButton: boolean = true; |
136 | 166 | }
|
0 commit comments