|
1 | 1 | import {Component, ViewChild} from '@angular/core';
|
2 | 2 | import {By} from '@angular/platform-browser';
|
3 |
| -import {ComponentFixture, TestBed, async, inject} from '@angular/core/testing'; |
| 3 | +import {ComponentFixture, TestBed, async, inject, fakeAsync, tick} from '@angular/core/testing'; |
4 | 4 | import {Directionality} from '@angular/cdk/bidi';
|
5 | 5 | import {dispatchKeyboardEvent} from '@angular/cdk/testing';
|
6 | 6 | import {ESCAPE, A} from '@angular/cdk/keycodes';
|
@@ -210,18 +210,37 @@ describe('Overlay directives', () => {
|
210 | 210 | fixture.componentInstance.isOpen = true;
|
211 | 211 | fixture.detectChanges();
|
212 | 212 |
|
213 |
| - let backdrop = overlayContainerElement.querySelector('.cdk-overlay-backdrop'); |
214 |
| - expect(backdrop).toBeTruthy(); |
| 213 | + expect(overlayContainerElement.querySelector('.cdk-overlay-backdrop')).toBeTruthy(); |
215 | 214 | });
|
216 | 215 |
|
217 | 216 | it('should not create the backdrop by default', () => {
|
218 | 217 | fixture.componentInstance.isOpen = true;
|
219 | 218 | fixture.detectChanges();
|
220 | 219 |
|
221 |
| - let backdrop = overlayContainerElement.querySelector('.cdk-overlay-backdrop'); |
222 |
| - expect(backdrop).toBeNull(); |
| 220 | + expect(overlayContainerElement.querySelector('.cdk-overlay-backdrop')).toBeNull(); |
223 | 221 | });
|
224 | 222 |
|
| 223 | + it('should be able to change hasBackdrop after the overlay has been initialized', |
| 224 | + fakeAsync(() => { |
| 225 | + // Open once with a backdrop |
| 226 | + fixture.componentInstance.hasBackdrop = true; |
| 227 | + fixture.componentInstance.isOpen = true; |
| 228 | + fixture.detectChanges(); |
| 229 | + |
| 230 | + expect(overlayContainerElement.querySelector('.cdk-overlay-backdrop')).toBeTruthy(); |
| 231 | + |
| 232 | + fixture.componentInstance.isOpen = false; |
| 233 | + fixture.detectChanges(); |
| 234 | + tick(500); |
| 235 | + |
| 236 | + // Open again without a backdrop. |
| 237 | + fixture.componentInstance.hasBackdrop = false; |
| 238 | + fixture.componentInstance.isOpen = true; |
| 239 | + fixture.detectChanges(); |
| 240 | + |
| 241 | + expect(overlayContainerElement.querySelector('.cdk-overlay-backdrop')).toBeFalsy(); |
| 242 | + })); |
| 243 | + |
225 | 244 | it('should set the custom backdrop class', () => {
|
226 | 245 | fixture.componentInstance.hasBackdrop = true;
|
227 | 246 | fixture.componentInstance.isOpen = true;
|
|
0 commit comments